简体   繁体   中英

How to maintain session timeout for long period in asp.net mvc4?

I have done some modifications in Web.config and globals.asax file giving some extra time limit, but the session is not working for the given time. Sometimes getting expired very soon.

Web.config:

 <sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="60000"/>

 <authentication mode="Forms">
      <forms loginUrl="~/Home/Login" timeout="28880"/>
 </authentication>

Global.asax/session_start():

 Session.Timeout = 1200;

I added namespaces for the session wherever required, but still the session problem persists, session is stateless after all coding is done.

Please can anyone suggest a proper solution, or if my flow is ambiguous, please let me know how to do it in a standard manner.

Thanks. Help will be appreciated.

You are providing timeout in 2 different places I mean u need to provide timeout either in web.config or in global.asax file so better remove timeout declaration from global.asax..

as documeneted here http://www.aspdotnet-suresh.com/2010/10/session-timeout-problem-in-aspnet.html :-

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;
> 
> }

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 above solution doesn't work than remove

<authentication mode="Forms">
  <forms timeout="50"/>

from web.config file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM