In this post we will discuss how to optimize session state in asp.net. As sessions are stored in the sever so it is very much important to optimize session, so that performance will be better.
You can also check out my previous posts on: Anonymous Types in C#.Net , Working with enterprise library for data access in asp.net Part-3 and RegularExpressionValidator example in Asp.Net.
– If no session is required for the application then make the session state mode as off in the web.config file like below:
When session state mode is off, Session will not be created for the client request. This will improve the performance of the web server.
– Suppose in a page you need only to read session then try to implement page level session like below:
<% @ Page ……. EnableSession=”ReadOnly” %>
– In a pag if you do not need session then disable the session like below:
<% @ Page ……. EnableSession=”False” %>
– If you need read and write to session then enable the session for the page.
<% @ Page ……. EnableSession=”True” %>
This way you can make some optimization of the session.