The SessionState attribute is very useful if you are using mvc3. How to achieve this using mvc2 requires a bit more coding.
The idea is to tell asp.net that the particular request is not using a session object.
So, create your own route handler for specific requests.
public class CustomRouteHandler : IRouteHandler { public System.Web.IHttpHandler GetHttpHandler(RequestContext requestContext) { requestContext.HttpContext.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.ReadOnly); return new MvcHandler(requestContext); } }
SessionStateBehavior enum has 4 members, you must use the "disabled" or "readonly" modes to get asynchronous behavior.
After creating this custom route handler, make sure your specific requests go through that handler. This can be done by defining new routes in Global.asax
routes.Add("Default", new Route( "{controller}/{action}", new RouteValueDictionary(new { controller = "Home", action = "Index"}), new CustomRouteHandler() ));
Adding this route makes all your requests handled by your route handler class. You can do this in a specific way by defining different routes.
Serdar Feb 11 2018-12-12T00: 00Z
source share