How to disable Session state on your asp.net page

Every asp.net page has the session state by default, this may decrease the total performance a little bit. So You can disable the session state from the pages when you don’t need to use sessions. And you can do so to set the false value of the EnableSessionState attribute in the page directive of your page like as:

<%@ page EnableSessionState="False" %>

Full deceleration:

<%@ Page Title="Home Page" Language="C#" EnableSessionState="False" 
 AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Basically EnableSessionState can have three values: False, ReadOnly and True. Suppose if you want to read the values from the session only then you can set the ReadOnly to the EnableSessionState attribute.

And Now if you want to disable Session state on entire website then you can change your website’s web.config file by just adding following lines:

<configuration>
  <system.web>
    <sessionState mode="Off">
    </sessionState> 
    </system.web>
</configuration>

Once you set the disable session state from the web.config, after that you can use the EnableSessionState=”True” in any page of your website.