TestUser001 - 2024/12/6 16:58:09
我在模板中设置了session,但Timeout似乎不起作用,大概十来二十分钟session就失效了,是哪里设置不对吗?
- Session.Timeout=120;
- Session["userid"]=userid;
- Session["username"]=username;
复制代码
xiyou - 2024/12/7 14:47:52
修改web.config的sessionState配置
TestUser001 - 2024/12/9 15:28:43
<system.web>
<!--
targetFramework注意版本,开发环境为4.6.1,但是部分虚拟主机(如阿里云虚拟主机)只支持4.5,如果服务器不支持.NET Framework4.6.1,可自行修改targetFramework="4.5"的版本号
-->
<compilation targetFramework="4.5" />
<!--
httpRuntime节点的maxRequestLength的单位为kb,根据实际需求设置,不要设置太大,避免存在恶意请求占用服务器资源
-->
<httpRuntime targetFramework="4.5" maxRequestLength="10240" executionTimeout="6000" enableVersionHeader="false" />
<httpModules />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" />
<httpCookies httpOnlyCookies="true" requireSSL="false" domain="" />
<sessionState mode="InProc" cookieName="sid" cookieless="false" stateConnectionString="tcpip=127.0.0.1:42424" timeout="120" />
<customErrors mode="Off" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
</system.web>
设置了并且重起了网站,还是一样不起作用。
xiyou - 2024/12/10 10:55:07
把cookieName="sid" 删除试试
TestUser001 - 2024/12/10 14:49:50
还是一样20分钟就失效了
xiyou - 2024/12/10 15:50:32
session不行就用cookie做好了,cookie做一下简单加密解密处理。