Introduction:
Here I will explain how to set session timeout in web.config,IIS and in application using asp.net
manually.
Description:
By default our websites session timeout is 20 mins after that session
will gets expire suppose if we want to set our custom timeout in our
applications we can set it in different ways (web.config, global.asax and in
IIS)
Check below methods to set session timeout in web.config,
global.asax and in iis
In Web.config file we can set session timeout like as shown below
<configuration>
<system.web>
<sessionState mode="InProc" timeout="60">
</sessionState>
</system.web>
</configuration>
|
In Global.asax file we can set session timeout
in Session_Start event like this
void Session_Start(object
sender, EventArgs e)
{
// Code that runs when a new
session is started
Session.Timeout = 15;
}
|
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
Once open Session State
set timeout in under cookie settings section like as shown below
If you set session time out in both web.config and in your iis the
iis session out value overrides web.config session time out
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
12 comments :
I have been facing this problem since many days, now its solved only becoz of U
Thank U so much
it is not working using webconfig
Please reply this coding is not working in webconfig file or global.asax file
This code need some correction.
However it logically excellent
Correct code is:
<sessionState mode="InProc" cookieless="true" timeout="60">
</sessionState>
Note; closing tag and white space at timeout was the problem.
Also code at
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Timeout = 15;
}
doesnot works at all.
hi sir, thanks for your beautiful explanation of each topic. I have a small doubt in this topic about of time we are giving. Is it in seconds or in minutes? (in webconfig and in global files)
@Thanks Asif... for finding my error
@rajnish... i updated the code...Please check it
send me the full code fro session time out on logout button click in.simple asp.net aspx page and .cs page...
my id is ankur03shukla@gmail.com
Plz give me the sample asax file for start the session and stop the session.
Why I am getting session timeout when I do some change in business logic
good
how to configure session state..?
Sir, I want to override the session timeout duration of iis server . How i can override iis session duration by c# code?
Note: Only a member of this blog may post a comment.