user215361
user215361

Reputation:

Get the session timeout value when it's not set in the configuration?

I am implementing my own session provider, and would like to know if the default of 20 minutes is set in the session provider automatically? Is this value provided whether or not an entry is in the configuration file?

If not should my session provider is supposed to get it from another location?

Upvotes: 12

Views: 27580

Answers (5)

Stephan Ahlf
Stephan Ahlf

Reputation: 3497

Try using:

System.Int64 timeout = System.Web.HttpContext.Current.Session.Timeout; // The time-out period, in minutes

Upvotes: 12

user215361
user215361

Reputation:

I couldn't find the value in a global configuration file, but it's defined somewhere.

Using the following code you can get the session timeout value whether or not it is defined in your local web.config.

Configuration conf = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
SessionStateSection section = (SessionStateSection) conf.GetSection("system.web/sessionState");
int timeout = (int) section.Timeout.TotalMinutes;

Upvotes: 18

antar
antar

Reputation: 510

In Global.asax, you can set

Session.TimeOut

in Session_Start or set it in other place in the code.

Upvotes: 1

G_P
G_P

Reputation: 2168

You can just use Session.Timeout to get the value

Upvotes: 0

Jeff Turner
Jeff Turner

Reputation: 1347

http://msdn.microsoft.com/en-us/library/aa478952.aspx

According to the article I've linked above, if the Timeout value is not set anywhere, a default of 20 minutes will be used. This seems to be the case for both custom providers and built-in.

Upvotes: 0

Related Questions