Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you programmatically change session time out in ASP.NET?

Can it be done or the only way is to configure it on IIS?

like image 871
juan Avatar asked Oct 24 '08 20:10

juan


3 Answers

You edit generally the Global.asax file's Session_Start method and set Session.TimeOut to whatever you want. You can do this anywhere else in your code too.

like image 174
wprl Avatar answered Nov 08 '22 02:11

wprl


you can, but it will not override the IIS settings (by default 20 minutos) if you are in a Shared Hosted environment.

what I do is apply the use of SQL Sessions, it will turn the web application a little more slow, but you have total control of the sessions and if you update something to the application and the Compiler needs to re-compile the resources/classes again, the user will not be logged out.

Sessions will be kept in a special table of the SQL database.

like image 20
balexandre Avatar answered Nov 08 '22 02:11

balexandre


If your in a hosted environment and your not allowed to override IIS default session timeout (as others have mentioned in the comments), you can trick IIS into keeping the session alive for longer by using an iframe that refreshes the session over and over (kind of like a keep alive ping) for whatever interval of time you need. I had this situation and used this approach

ASP.NET Push Redirect on Session Timeout

like image 20
Chris Smith Avatar answered Nov 08 '22 02:11

Chris Smith