What is default session timeout in ASP.NET?
Asked Answered
H

5

111

What is the default session timeout value in ASP.NET?

Harakiri answered 16/5, 2009 at 6:33 Comment(0)
G
107

It is 20 Minutes according to MSDN

From MSDN:

Optional TimeSpan attribute.

Specifies the number of minutes a session can be idle before it is abandoned. The timeout attribute cannot be set to a value that is greater than 525,601 minutes (1 year) for the in-process and state-server modes. The session timeout configuration setting applies only to ASP.NET pages. Changing the session timeout value does not affect the session time-out for ASP pages. Similarly, changing the session time-out for ASP pages does not affect the session time-out for ASP.NET pages. The default is 20 minutes.

Grolier answered 16/5, 2009 at 6:38 Comment(0)
M
48

It depends on either the configuration or programmatic change.
Therefore the most reliable way to check the current value is at runtime via code.

See the HttpSessionState.Timeout property; default value is 20 minutes.

You can access this propery in ASP.NET via HttpContext:

this.HttpContext.Session.Timeout // ASP.NET MVC controller
Page.Session.Timeout // ASP.NET Web Forms code-behind
HttpContext.Current.Session.Timeout // Elsewhere
Mandal answered 2/6, 2011 at 7:29 Comment(2)
i am able to get the value 20 while checking int check = this.HttpContext.Session.Timeout; but can i set session timeout with key ? and check session timeout for particular key like: Session["mykey"] ?Mender
for those of you who didn't click the MSDN link, the Timeout property value is in minutesLowerclassman
L
38
  1. The Default Expiration Period for Session is 20 Minutes.
  2. The Default Expiration Period for Cookie is 30 Minutes.
  3. Maximum Size of ViewState is 25% of Page Size
Longdistance answered 29/4, 2015 at 13:27 Comment(0)
D
26

The default is 20 minutes. http://msdn.microsoft.com/en-us/library/h6bb9cz9(v=vs.80).aspx

<sessionState 
mode="[Off|InProc|StateServer|SQLServer|Custom]"
timeout="number of minutes"
cookieName="session identifier cookie name"
cookieless=
     "[true|false|AutoDetect|UseCookies|UseUri|UseDeviceProfile]"
regenerateExpiredSessionId="[True|False]"
sqlConnectionString="sql connection string"
sqlCommandTimeout="number of seconds"
allowCustomSqlDatabase="[True|False]"
useHostingIdentity="[True|False]"
stateConnectionString="tcpip=server:port"
stateNetworkTimeout="number of seconds"
customProvider="custom provider name">
<providers>...</providers>
</sessionState>
Destroy answered 12/12, 2012 at 6:48 Comment(1)
This code goes in the <system.web> section of the web.config fileFirstfoot
B
4

The Default Expiration Period for Session is 20 Minutes.

You can update sessionstate and configure the minutes under timeout

<sessionState 
timeout="30">
</sessionState>
Bukharin answered 25/7, 2017 at 11:45 Comment(1)
This code goes in the <system.web> section of the web.config fileFirstfoot

© 2022 - 2024 — McMap. All rights reserved.