【问题标题】:Session timeout could not be changed无法更改会话超时
【发布时间】:2015-04-06 15:51:30
【问题描述】:

我在 myasp.net 中有 asp 主机,我尝试将会话超时更改为 24 小时,但几分钟后服务器仍断开用户连接。 我尝试使用 c# 代码,例如:

Session.Timeout = 3600;

这是 web.config 的样子:

    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="owin:AutomaticAppStartup" value="false"/>
  </appSettings>

  <system.web>
     <sessionState mode="InProc" cookieless="false" timeout="80" />
    <authentication mode="Forms">
      <forms timeout="60" />
      </authentication>

    <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime executionTimeout="180" targetFramework="4.5" maxRequestLength="13107200" />
  <customErrors mode="Off" />
  </system.web>
<system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这个问题有解决办法吗?

【问题讨论】:

  • 在 IIS 中设置的超时时间是多少?你有没有检查那里进行设置更改

标签: c# asp.net iis iis-7


【解决方案1】:

Session.Timeout 不是您唯一应该关心的事情。 IIS 的回收超时通常设置为 20 分钟,这会导致应用程序池在该时间之后释放其内存。你也应该改变它。

作为另一个建议,考虑使用StateServer 而不是InProc,并将debug 设置为false(当然是在生产环境中)以获得更可靠的会话体验。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-09-27
  • 2012-04-30
  • 2015-01-10
  • 2011-09-04
  • 2012-01-08
相关资源
最近更新 更多