0% found this document useful (0 votes)
106 views3 pages

Optimize Session State in MVC4

The document discusses controlling session behavior in ASP.NET MVC4. It explains that by default, ASP.NET MVC supports session state to store data across requests, but this can impact performance. The SessionState attribute provides control over session behavior by specifying an enumeration value like Disabled, ReadOnly or Required. Disabling session for controllers that don't need it can improve performance slightly. TempData uses session state so exceptions may occur if session is disabled for a controller.

Uploaded by

krishanmanral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views3 pages

Optimize Session State in MVC4

The document discusses controlling session behavior in ASP.NET MVC4. It explains that by default, ASP.NET MVC supports session state to store data across requests, but this can impact performance. The SessionState attribute provides control over session behavior by specifying an enumeration value like Disabled, ReadOnly or Required. Disabling session for controllers that don't need it can improve performance slightly. TempData uses session state so exceptions may occur if session is disabled for a controller.

Uploaded by

krishanmanral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

11/13/2014

Controlling Session Behavior in [Link] MVC4

Controlling Session Behavior in [Link] MVC4


P o st e d By : S h aile ndra Ch auh an, 0 6 Jan 2 0 13
U pdat e d On : 11 Jun 2 0 14
Total Views : 122,062
Version Support : MVC3 & MVC4
Keywords : Session state in mvc,disable session in mvc,session less controller,session less
action method

y default, [Link] 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 [Link] 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.

Session Less Controller


If some of the controllers of your [Link] 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 [Link] MVC4, SessionState attribute provides you more control over the behavior of session-state by
specifying the value of SessionStateBehavior enumeration as shown below:

SessionStateBehavior Enumeration's Value


Value

Description

Default

The default [Link] 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.

[Link]

1/3

11/13/2014

Controlling Session Behavior in [Link] MVC4

In [Link] MVC, TempData use session state for storing the data values across requests. Hence, when you
will disabled the session state for the controller, it will throw the exception as shown below:

What do you think?


I hope you will enjoy the tips while programming with [Link] MVC. I would like to have feedback from my
blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Share this article with your friends!


inShare4

About the Author

[Link]

2/3

11/13/2014

Controlling Session Behavior in [Link] MVC4

Hey! I'm Shailendra Chauhan author, developer with more than 5 years of hand over Microsoft .NET
technologies. I am a .NET Consultant, founder & chief editor of [Link] and
[Link]. I am author of books [Link] MVC Interview Questions and Answers &
LINQ Interview Questions and Answers.
I love to work with web applications and mobile apps using Microsoft technology including [Link],
MVC, C#, SQL Server, WCF, Web API, Entity Framework,Cloud Computing, Windows Azure, jQuery, jQuery
Mobile, [Link], [Link] and many more web technologies. More...

[Link]

3/3

You might also like