How to control Session behavior in ASP.NET MVC?

By default, ASP.NET MVC support session state. Session is used to store data values across requests. Whether you store some data values with in the session or not ASP.NET MVC must manage the session state for all the controllers in your application that is time consuming. Since, session is stored on server side and consumes server memory, hence it also affect your application performance.
If some of the controllers of your ASP.NET MVC application are not using session state features, you can disable session for those controller and can gain slight performance improvement of your application. You can simplify session state for your application by using available options for session state.
In ASP.NET MVC4, SessionState attribute provides you more control over the behavior of session-state by specifying the value of SessionStateBehavior enumeration as shown below:

Value Description
Default The default ASP.NET behavior is used to determine the session state behavior.
Disabled Session state is disabled entirely.
ReadOnly Read-only session state behavior is enabled.
Required Full read-write session state behavior is enabled.

Tagged , . Bookmark the permalink.

Leave a Reply