How to Set a Session in ASP.Net Website

Introduction

In asp.net website, You can set a session in three ways.

In web.config file
In Global.asax file and
IIS Seting

Web.config file

In Web.config file we can set session timeout like as shown below .

<configuration>

<system.web>

 <sessionState mode="InProc" cookieless="true"timeout="60"/>

 </sessionState>

 </system.web>

</configuration>


In Global.asax

void Session_Start(object sender, EventArgs e)

{

// Code that runs when a new session is started

Session.Timeout = 15;

}

IIS Setting

In IIS setting you can also set default session timeout.

  1. Open IIS start-->run type-->inetmgr and press enter.
  2. Right Click on "Default Web Site" go to properties
  3. Select Asp.Net tab, click on "Edit Configuration" Button 
  4. Select "State Management tab" in new popup window

In case if you are using IIS7

Select Default Web Site >> Click on Session State

Ebook Download
View all
Learn
View all