Showing posts with label disable session state. Show all posts
Showing posts with label disable session state. Show all posts

March 06, 2011

ASP.NET Performance Tip2

Read Tip1 Here

2.  Disable Session State

In ASP.NET Session State  is on by default for every page . So we need to disable Session State if we are not going to use it.  Sessions are created to  pass information from one page to other page per user. We do not require Session State when web pages are static or when there is no need to store information captured in the page.  Do not use sessions to store Global data that is specific to all users. Session is specific to single user.

We can this off for specific pages, as well as entire page depending on the requirement. Usage of sessions will significantly decrease the performance of the application .  So we need to try to minimize the use of  sessions in Web Applications.  If we are not using Sessions in the application it can be set off in the web.config that applies to entire application.

Otherwise it can be disabled in page level as

<%@ Page language="c#" Codebehind="Form.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.Form" EnableSessionState="false" %>


In web.config  we can turn off sessionstatemode under System.Web Section as follows.

<sessionState mode="off"></sessionState>

As all of us know,ASP.NET Manages session state automatically. But if we do not require Sessions, disabling it will help in boosting the performance of the application.