How can I set infinity session time out in asp.net project

↘锁芯ラ 提交于 2020-01-14 09:45:15

问题


I'm working on asp.net project. how can I increase the session timeout? (infinity timeout) Or should I do this on IIS? If it is possible, please explain.


回答1:


You can set session timeout in web.config as shown below. The value is showing minutes, so you can set as long as you want, up until a year.

    <configuration>
      <system.web>
         <sessionState timeout="200"></sessionState>
      </system.web>
    </configuration>

The Timeout property can be set in the Web.config file for an application using the timeout attribute of the sessionState configuration element, or you can set the Timeout property value directly using application code.

The Timeout property cannot be set to a value greater than 525,600 minutes (1 year). The default value is 20 minutes.




回答2:


one way is by setting the timeout in web.config file. Like

<configuration>
<system.web>
    <sessionState mode="InProc" timeout="120"/>
</system.web>
</configuration>

The other way is by setting the time-out in server side code in .cs file. Like

Session.Timeout = 100;

The time-out value entered will be read as minutes. If set to 0, then there will be an error page displaying session time-out value cannot be 0 and must be >0.




回答3:


You cannot assign it to unlimited. You can increase the value in minutes using the time out attribute of Session state element in web.config

<sessionState timeout="30">
</sessionState>

By default session timeout value is 20 minutes. Also in your case if you are using forms authentication, check the authentication time out value as well

<authentication mode="Forms">
   <forms loginUrl="logon.aspx"  protection="All" path="/" timeout="30" />
</authentication> 


来源:https://stackoverflow.com/questions/31239448/how-can-i-set-infinity-session-time-out-in-asp-net-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!