能否以编程方式更改 ASP.NET 中的会话超时?
可以吗,还是只能在IIS上配置?
Can it be done or the only way is to configure it on IIS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
可以吗,还是只能在IIS上配置?
Can it be done or the only way is to configure it on IIS?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您通常编辑 Global.asax 文件的 Session_Start 方法并设置 Session.TimeOut 为您想要的任何内容。 您也可以在代码中的其他任何地方执行此操作。
You edit generally the Global.asax file's Session_Start method and set Session.TimeOut to whatever you want. You can do this anywhere else in your code too.
您可以,但如果您处于共享托管环境中,它不会覆盖 IIS 设置(默认为 20 分钟)。
我所做的是使用 SQL 会话,它会使 Web 应用程序变慢一点,但您可以完全控制会话,如果您更新应用程序的某些内容,并且编译器需要再次重新编译资源/类,用户将不会注销。
会话将保存在 SQL 数据库的一个特殊表中。
you can, but it will not override the IIS settings (by default 20 minutos) if you are in a Shared Hosted environment.
what I do is apply the use of SQL Sessions, it will turn the web application a little more slow, but you have total control of the sessions and if you update something to the application and the Compiler needs to re-compile the resources/classes again, the user will not be logged out.
Sessions will be kept in a special table of the SQL database.
如果您在托管环境中并且不允许覆盖 IIS 默认会话超时(正如其他人在评论中提到的那样),您可以通过使用反复刷新会话的 iframe 来欺骗 IIS 让会话保持更长时间(类似于就像保持活动 ping 一样)无论您需要什么时间间隔。 我遇到了这种情况并使用了这种方法
ASP.NET 推送重定向会话超时
If your in a hosted environment and your not allowed to override IIS default session timeout (as others have mentioned in the comments), you can trick IIS into keeping the session alive for longer by using an iframe that refreshes the session over and over (kind of like a keep alive ping) for whatever interval of time you need. I had this situation and used this approach
ASP.NET Push Redirect on Session Timeout