Session timeout in ASP.NET

后端 未结 15 2165
忘了有多久
忘了有多久 2020-11-22 09:14

I am running an ASP.NET 2.0 application in IIS 6.0. I want session timeout to be 60 minutes rather than the default 20 minutes. I have done the following

  1. Set <
相关标签:
15条回答
  • 2020-11-22 09:43

    You can find the setting here in IIS:

    It can be found at the server level, web site level, or app level under "ASP".

    I think you can set it at the web.config level here. Please confirm this for yourself.

    <configuration>
       <system.web>
    
          <!-- Session Timeout in Minutes (Also in Global.asax) -->
           <sessionState timeout="1440"/>
    
       </system.web>
    </configuration>
    
    0 讨论(0)
  • 2020-11-22 09:44

    https://usefulaspandcsharp.wordpress.com/tag/session-timeout/

    <authentication mode="Forms">
      <forms loginUrl="Login.aspx" name=".ASPXFORMSAUTH" timeout="60" slidingExpiration="true" />
    </authentication>
    
    <sessionState mode="InProc" timeout="60" />
    
    0 讨论(0)
  • 2020-11-22 09:47

    Since ASP.Net core 1.0 (vNext or whatever name is used for it) sessions are implemented differently. I changed the session timeout value in Startup.cs, void ConfigureServices using:

    services.AddSession(options => options.IdleTimeout = TimeSpan.FromSeconds(42));
    

    Or if you want to use the appsettings.json file, you can do something like:

    // Appsettings.json
    "SessionOptions": {
        "IdleTimeout": "00:30:00"
    }
    
    // Startup.cs
    services.AddSession(options => options.IdleTimeout = TimeSpan.Parse(Config.GetSection("SessionOptions")["IdleTimeout"]));
    
    0 讨论(0)
  • 2020-11-22 09:50

    Do you have anything in machine.config that might be taking effect? Setting the session timeout in web.config should override any settings in IIS or machine.config, however, if you have a web.config file somewhere in a subfolder in your application, that setting will override the one in the root of your application.

    Also, if I remember correctly, the timeout in IIS only affects .asp pages, not .aspx. Are you sure your session code in web.config is correct? It should look something like:

    <sessionState
        mode="InProc"
        stateConnectionString="tcpip=127.0.0.1:42424"
        stateNetworkTimeout="60"
        sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
        cookieless="false"
        timeout="60"
    />
    
    0 讨论(0)
  • 2020-11-22 09:53

    That is usually all that you need to do...

    Are you sure that after 20 minutes, the reason that the session is being lost is from being idle though...

    There are many reasons as to why the session might be cleared. You can enable event logging for IIS and can then use the event viewer to see reasons why the session was cleared...you might find that it is for other reasons perhaps?

    You can also read the documentation for event messages and the associated table of events.

    0 讨论(0)
  • 2020-11-22 09:54

    IIS sessions timeout value is for classic .asp applications only, this is controlled on IIS configuration. In your case For ASP.NET apps, only the web.config-specified timeout value applies.

    0 讨论(0)
提交回复
热议问题