asp.net mvc - MVC Razor ViewEngine not thread-safe? -
i have .net mvc3 application responsible managing similar views in multiple locations use same controllers e.g site1/v1/views/index.cshtml
, site1/v2/views/index.cshtml
.
the way handled creating customcontrollerfactory inherits defaultcontrollerfactory , in createcontroller method, clear existing view engines , add new custom viewengine specifies view location formats based off current url.
if user lands on site1.com/v1/index.cshtml
, viewengine specify view locations of :
string versiondirectory = "v1"; viewlocationformats = new[]{ versiondirectory + "/views/{0}.cshtml", "/views/{0}.cshtml", "~/shared/{0}.cshtml" };
the problem having if multiple users land on different pages @ same time users see same view.
initially thought related caching, after explicitly setting usecache = false
in custom viewengine, seems has got more viewengines class not being thread safe.
does have ideas how can accomplish same result, in different way?
thanks in advance.
the viewengines collection static collection , values shared across requests. attempting possible, way doing not correct.
one easy approach write custom view engine derives razorviewengine , override findview method. method called once per request. in implementation, call base.findview , modify result (if it's not null) include site information need.
scott hanselman has blog post shows 1 example of looking in location views via custom view engine. http://www.hanselman.com/blog/abetteraspnetmvcmobiledevicecapabilitiesviewengine.aspx
Comments
Post a Comment