ASP.NET 中的会话超时

发布于 2024-07-14 21:59:07 字数 328 浏览 4 评论 0原文

我正在 IIS 6.0 中运行 ASP.NET 2.0 应用程序。 我希望会话超时为 60 分钟,而不是默认的 20 分钟。 我已经完成了以下

  1. 设置 web.config中。
  2. 在 IIS 管理器/网站属性/ASP.NET 配置设置中将会话超时设置为 60 分钟。
  3. 在应用程序池属性/性能中将空闲超时设置为 60 分钟。

我仍然遇到 20 分钟的会话超时。 我还有什么需要做的吗?

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 <sessionState timeout="60"></sessionState>
    in web.config.
  2. Set session timeout to 60 minutes in IIS manager/Web site properties/ASP.NET configuration settings.
  3. Set idle timeout to 60 minutes in application pool properties/performance.

I am still getting a session timeout at 20 minutes. Is there anything else I need to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

极致的悲 2024-07-21 21:59:07

您使用表单身份验证吗?

表单身份验证使用自己的超时值(默认为 30 分钟)。 表单身份验证超时会将用户发送到登录页面,且会话仍处于活动状态。 这可能看起来像您的应用程序在会话超时时给出的行为,因此很容易将其中一个与另一个混淆。

<system.web>
    <authentication mode="Forms">
          <forms timeout="50"/>
    </authentication>

    <sessionState timeout="60"  />
</system.web>

将表单超时设置为小于会话超时可以为用户提供一个重新登录的窗口,而不会丢失任何会话数据。

Are you using Forms authentication?

Forms authentication uses it own value for timeout (30 min. by default). A forms authentication timeout will send the user to the login page with the session still active. This may look like the behavior your app gives when session times out making it easy to confuse one with the other.

<system.web>
    <authentication mode="Forms">
          <forms timeout="50"/>
    </authentication>

    <sessionState timeout="60"  />
</system.web>

Setting the forms timeout to something less than the session timeout can give the user a window in which to log back in without losing any session data.

流绪微梦 2024-07-21 21:59:07

我不知道 web.config 或 IIS。
但我相信从 C# 代码中你可以做到这一点

Session.Timeout = 60; // 60 is number of minutes

I don't know about web.config or IIS.
But I believe that from C# code you can do it like

Session.Timeout = 60; // 60 is number of minutes
树深时见影 2024-07-21 21:59:07

在 web.config 文件中使用以下代码块。
这里默认会话超时为 80 分钟。

<system.web>
 <sessionState mode="InProc" cookieless="false" timeout="80" />
</system.web>

使用以下链接获取带有弹出警报消息的会话超时。

会话超时示例

仅供参考:上面的示例是使用 devexpress 弹出控件完成的,因此您需要使用普通弹出控件自定义/替换 devexpress 弹出控件。 如果您使用 devexpress 则无需自定义

Use the following code block in your web.config file.
Here default session time out is 80 mins.

<system.web>
 <sessionState mode="InProc" cookieless="false" timeout="80" />
</system.web>

Use the following link for Session Timeout with popup alert message.

Session Timeout Example

FYI:The above examples is done with devexpress popup control so you need to customize/replace devexpress popup control with normal popup control. If your using devexpress no need to customize

甜尕妞 2024-07-21 21:59:07

在我的情况下,它是应用程序池。 它设置为在空闲 xx 分钟后重新启动。 当我将其设置为不重新启动时,它似乎使用 Web Config 中的值。

In my situation, it was Application Pool. It is set to restart when idle for xx mins. When I set it to not restart, it seems to use value from Web Config.

猫卆 2024-07-21 21:59:07

machine.config 中是否有任何可能生效的内容? 在 web.config 中设置会话超时应覆盖 IIS 或 machine.config 中的任何设置,但是,如果应用程序的子文件夹中某处有 web.config 文件,则该设置将覆盖应用程序根目录中的设置。

另外,如果我没记错的话,IIS 中的超时仅影响 .asp 页面,而不影响 .aspx。 您确定 web.config 中的会话代码正确吗? 它应该看起来像:

<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"
/>

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"
/>
橪书 2024-07-21 21:59:07

这通常就是您需要做的所有事情...

您确定 20 分钟后,会话丢失的原因是由于空闲...

会话可能被清除的原因有很多。 您可以启用 IIS 的事件日志记录,然后使用事件查看器查看会话被清除的原因...您可能会发现它可能是出于其他原因?

您还可以阅读事件消息文档以及相关的事件表

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.

心舞飞扬 2024-07-21 21:59:07

自 ASP.Net core 1.0(vNext 或任何名称)以来,会话的实现方式有所不同。
我使用以下方法更改了 Startup.csvoid ConfigureServices 中的会话超时值:

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

或者,如果您想使用 appsettings.json 文件,您可以做类似的事情:

// Appsettings.json
"SessionOptions": {
    "IdleTimeout": "00:30:00"
}

// Startup.cs
services.AddSession(options => options.IdleTimeout = TimeSpan.Parse(Config.GetSection("SessionOptions")["IdleTimeout"]));

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"]));
情魔剑神 2024-07-21 21:59:07

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" />

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" />
唐婉 2024-07-21 21:59:07

IIS 中的默认会话超时定义为 20 分钟

对于 IIS 8.5 Web 上托管的每个站点,请执行以下过程

IIS 超时配置

打开 IIS 8.5 管理器。

单击站点名称。

选择“管理”部分下的“配置编辑器”。

从配置顶部的“部分:”下拉列表中
编辑器中,找到“system.web/sessionState”。

将“超时”设置为“00:20:00 或更短”,使用最小值
可能取决于应用。 可接受的值为 5
高价值应用 10 分钟,中价值应用 10 分钟
应用程序,低价值应用程序 20 分钟。

在“操作”窗格中,单击“应用”。

The default session timeout is defined into IIS to 20 minutes

Follow the procedures below for each site hosted on the IIS 8.5 web

IIS Timeout configuration

Open the IIS 8.5 Manager.

Click the site name.

Select "Configuration Editor" under the "Management" section.

From the "Section:" drop-down list at the top of the configuration
editor, locate "system.web/sessionState".

Set the "timeout" to "00:20:00 or less”, using the lowest value
possible depending upon the application. Acceptable values are 5
minutes for high-value applications, 10 minutes for medium-value
applications, and 20 minutes for low-value applications.

In the "Actions" pane, click "Apply".

上课铃就是安魂曲 2024-07-21 21:59:07

如果您使用身份验证,我建议在 web.config 文件中添加以下内容。

就我而言,用户在超时时会被重定向到登录页面:

<authentication mode="Forms">
    <forms defaultUrl="Login.aspx" timeout="120"/>
</authentication>

If you are using Authentication, I recommend adding the following in web.config file.

In my case, users are redirected to the login page upon timing out:

<authentication mode="Forms">
    <forms defaultUrl="Login.aspx" timeout="120"/>
</authentication>
海的爱人是光 2024-07-21 21:59:07

您可以在 IIS 中找到该设置:

设置

它可以在“ASP”下的服务器级别、网站级别或应用程序级别找到。

我认为你可以在此处的 web.config 级别设置它。 请您亲自确认一下。

<configuration>
   <system.web>

      <!-- Session Timeout in Minutes (Also in Global.asax) -->
       <sessionState timeout="1440"/>

   </system.web>
</configuration>

You can find the setting here in IIS:

Settings

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>
寂寞笑我太脆弱 2024-07-21 21:59:07

如果您希望网站的会话超时,请

<authentication mode="Forms">
      <forms timeout="50"/>
</authentication>

从 web.config 文件中删除标签。

if you are want session timeout for website than remove

<authentication mode="Forms">
      <forms timeout="50"/>
</authentication>

tag from web.config file.

为人所爱 2024-07-21 21:59:07

Timeout 属性指定分配给应用程序的 Session 对象的超时期限(以分钟为单位)。 如果用户在超时时间内没有刷新或请求页面,则会话结束。

IIS 6.0:允许的最小值为 1 分钟,最大值为
1440 分钟。

Session.Timeout = 600;

The Timeout property specifies the time-out period assigned to the Session object for the application, in minutes. If the user does not refresh or request a page within the time-out period, the session ends.

IIS 6.0: The minimum allowed value is 1 minute and the maximum is
1440 minutes.

Session.Timeout = 600;
余罪 2024-07-21 21:59:07

更改 IIS 中的会话超时值后,请重新启动 IIS。
要实现此目的,请转到命令提示符。 键入 IISRESET 并按 Enter 键。

After changing the session timeout value in IIS, Kindly restart the IIS.
To achieve this go to command prompt. Type IISRESET and press enter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文