Is there any way to specify that a given Controller or Action uses Session state in a read-only manner? In "old" ASP.NET we used to do something like this:
<%@ Page EnableSessionState="ReadOnly" %>
Is there an ASP.NET MVC equivalent? I'm looking to allow my application to serve multiple requests from the same client simultaneously, and turning off session completely is -not- an option in my case.
Sessionless Controller We can disable the session for those controllers using the SessionStateAttribute (set session state Behavior to Disabled) and we can get a slight performance improvement for our application.
ASP.NET MVC provides three ways (TempData, ViewData and ViewBag) to manage session, apart from that we can use session variable, hidden fields and HTML controls for the same. But like session variable these elements cannot preserve values for all requests; value persistence varies depending the flow of request.
By default, Asp.Net MVC support session state.
In Asp.Net MVC3 there is now a SessionStateAttribute
that you can decorate your Controller with to force all actions into Read-Write, Read-only, or No session mode.
http://msdn.microsoft.com/en-us/library/system.web.mvc.sessionstateattribute(v=VS.98).aspx
A similar question was asked here: Disable Session state per-request in ASP.Net MVC
The accepted answer deals with creating a custom route handler that ultimately skips binding to the session. This doesn't exactly answer your question (which is how to declare multiple actions to use readonly session access), but it seemed relevant enough to mention.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With