asp.net 如何在www.example中增加会话超时 www.example.com

bsxbgnwa  于 2023-05-02  发布在  .NET
关注(0)|答案(6)|浏览(126)

我试着用下面的代码来增加会话超时时间,但没有用,
代码为:

<sessionState mode="InProc" cookieless="true" timeout="60">
</sessionState>

代码也在

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Timeout = 15;
}
blmhpbnm

blmhpbnm1#

您可以在www.example中增加会话超时。 www.example.com in any one of the following ways

    • 使用IIS版本7:**

1.打开IIS
1.从网站列表中选择您的网站
1.点击右侧【会话状态】
1.现在在cookie设置下输入您的会话超时

    • Web.config:打开您的网站。配置文件和系统下。web**部分添加以下内容:
<sessionState timeout = "20" mode = "InProc" />

用你想要的数字替换20。

    • 全局. asax文件:Session_Start方法下,将会话的timeout**属性设置为必填值,如下所示
Session.Timeout = "20";
    • 注意:**如果您在IIS和Web中都设置了会话超时。配置,那么IIS中的配置将覆盖Web中的配置。配置

希望这有帮助!

ioekq8ef

ioekq8ef2#

如果您使用的是表单身份验证,那么会话超时的默认值是30分钟。尝试此代码以增加会话超时。

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
  </authentication>
  <sessionstate timeout="80"/>
</system.web>

我认为代码可以帮助你。

gpnt7bae

gpnt7bae3#

只需转到WebConfig,然后设置它,

<system.web>
    <sessionState timeout="60"></sessionState>
  <compilation debug="true" targetFramework="4.0" />
</system.web>
oug3syen

oug3syen4#

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
  </authentication>
  <sessionState timeout="80"/>
</system.web>

这对我有用,复制到你的网站上。配置文件。

ibps3vxo

ibps3vxo5#

我想添加我的最终解决方案。在阅读后,在配置中设置它是“不正确的”。

if (model.RememberMe)
            {
                var ASPCookie = Request.Cookies["ASP.NET_SessionId"];
                ASPCookie.Expires = DateTime.Now.AddDays(15);
                Response.SetCookie(ASPCookie);
            }
svmlkihl

svmlkihl6#

<sessionState cookieless="false" timeout="30" mode="InProc"/>
  <authentication mode="Forms">
      <forms name="AppRootForms" loginUrl="LoginPage.aspx" protection="All" timeout="30" path="/" slidingExpiration="true"/>
    </authentication>
<system.webServer>
     <!--<max limit for storing session />-->
    <asp>
         <session allowSessionState="true" max="100000" timeout="00:30:00" />
    </asp>
</system.webServer>

相关问题