ASP.NET 中的会话超时
我正在 IIS 6.0 中运行 ASP.NET 2.0 应用程序。我希望会话超时为 60 分钟,而不是默认的 20 分钟。我已经完成了以下
- 设置
在web.config
中。 - 在 IIS 管理器/网站属性/ASP.NET 配置设置中将会话超时设置为 60 分钟。
- 在应用程序池属性/性能中将空闲超时设置为 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
- Set
<sessionState timeout="60"></sessionState>
inweb.config
. - Set session timeout to 60 minutes in IIS manager/Web site properties/ASP.NET configuration settings.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
您使用表单身份验证吗?
表单身份验证使用自己的超时值(默认为 30 分钟)。表单身份验证超时会将用户发送到登录页面,且会话仍处于活动状态。这可能看起来像您的应用程序在会话超时时给出的行为,因此很容易将其中一个与另一个混淆。
将表单超时设置为小于会话超时可以为用户提供一个重新登录的窗口,而不会丢失任何会话数据。
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.
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.
我不知道 web.config 或 IIS。
但我相信从 C# 代码中你可以做到这一点
I don't know about web.config or IIS.
But I believe that from C# code you can do it like
在 web.config 文件中使用以下代码块。
这里默认会话超时为 80 分钟。
使用以下链接获取带有弹出警报消息的会话超时。
会话超时示例
仅供参考:上面的示例是使用 devexpress 弹出控件完成的,因此您需要使用普通弹出控件自定义/替换 devexpress 弹出控件。如果您使用 devexpress 则无需自定义
Use the following code block in your web.config file.
Here default session time out is 80 mins.
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
在我的情况下,它是应用程序池。它设置为在空闲 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.
machine.config 中是否有任何可能生效的内容?在 web.config 中设置会话超时应覆盖 IIS 或 machine.config 中的任何设置,但是,如果应用程序的子文件夹中某处有 web.config 文件,则该设置将覆盖应用程序根目录中的设置。
另外,如果我没记错的话,IIS 中的超时仅影响 .asp 页面,而不影响 .aspx。您确定 web.config 中的会话代码正确吗?它应该看起来像:
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:
这通常就是您需要做的所有事情...
您确定 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.
自 ASP.Net core 1.0(vNext 或任何名称)以来,会话的实现方式有所不同。
我使用以下方法更改了
Startup.cs
、void ConfigureServices
中的会话超时值:或者如果您想使用
appsettings.json
文件,您可以做类似的事情: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:Or if you want to use the
appsettings.json
file, you can do something like:https://usefulaspandcsharp.wordpress.com/tag/session-timeout/
https://usefulaspandcsharp.wordpress.com/tag/session-timeout/
IIS 中的默认会话超时定义为 20 分钟
对于 IIS 8.5 Web 上托管的每个站点,请执行以下过程
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
如果您使用身份验证,我建议在 web.config 文件中添加以下内容。
就我而言,用户在超时时会被重定向到登录页面:
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:
您可以在 IIS 中找到该设置:
它可以在“ASP”下的服务器级别、网站级别或应用程序级别找到。
我认为你可以在此处的 web.config 级别设置它。请您亲自确认一下。
You can find the setting here in IIS:
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.
如果您希望网站的会话超时,请
从 web.config 文件中删除标签。
if you are want session timeout for website than remove
tag from web.config file.
Timeout 属性指定分配给应用程序的 Session 对象的超时期限(以分钟为单位)。如果用户在超时时间内没有刷新或请求页面,则会话结束。
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 中的会话超时值后,请重新启动 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.