管理 ASP.NET 中的会话超时

发布于 2024-08-22 07:06:42 字数 1201 浏览 4 评论 0原文

我有一个 ASP.NET 2.0 Web 应用程序与多个 ASP.NET 2.0 Web 服务通信。两者都使用 ASP.NET 会话来保存会话数据。

为了警告用户应用程序的会话超时,我使用了 Travis Collins 的超时控件 显示标题为“您的会话即将过期”的 ModalPopupExtender 以及“保持登录”和“注销”按钮。单击“保持登录”时,它会回调一个空方法,该方法会重置会话计时器(我相信是因为每个 HttpRequest 都会调用 ResetItemTimeout)。

为了防止服务中的会话在应用程序中的会话之前超时,我将它们的超时设置得更长,并计划在应用程序中重置会话计时器时对它们调用一个空方法。但是,没有 会话状态事件用于重置计时器。

我是否必须覆盖 ResetItemTimeout?我该怎么做? 或者是否有另一种方法可以实现我的目标(例如,在应用程序服务处于活动状态时保持服务会话处于活动状态)?我正在考虑扩展超时控制以通过应用程序发送心跳(例如 Tim Mackey 的想法) 。

I have a ASP.NET 2.0 Web Application talking to multiple ASP.NET 2.0 Web Services. Both use ASP.NET Sessions to persist session data.

To warn the user about session timeouts of the app, I use a modified version of Travis Collins's Timeout Control to show a ModalPopupExtender titled 'Your session is about to expire' and buttons 'Stay Logged In' and 'Logout'. On clicking 'Stay Logged In' it makes a callback to an empty method, which resets the session timer (I believe because each HttpRequest causes a call to ResetItemTimeout).

To prevent the session in the services timing out before the one in app, I set their timeouts to be longer, and planned to call an empty method on them whenever the session timer is reset in the app. However, there is no Session-State Event for the timer being reset.

Do I have to override ResetItemTimeout? How do I do this?
Or is there another way to acheive my aim (e.g. keep the service session alive whilst the app service is alive)? I'm considering extending my timeout control to send heartbeats via the app (like Tim Mackey's idea).

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

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

发布评论

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

评论(3

水溶 2024-08-29 07:06:42

我不确定我是否遵循。您是说在 Web 服务上调用空方法不会重置会话计时器吗?

此外,这似乎是一个很大的开销。为什么不将 Web 应用程序和 Web 服务设置为使用相同的会话 cookie?

I'm not sure I follow. Are you saying that calling an empty method on the webservice does not reset the session timer?

Additionally, this seems like a lot of overhead. Why not set the web application and the web services to use the same session cookies?

可可 2024-08-29 07:06:42

当 .Net 应用程序调用 Web 服务时,.Net Web 应用程序就是客户端并拥有会话。在最好的情况下,Web 服务的会话特定于 .Net Web 应用程序,而不是特定于使用浏览器的用户(Web 应用程序的客户端)。

我认为默认情况是每次进行 Web 服务调用时会话都会启动(Web 服务调用不保存会话状态所需的 cookie),因此它不会在调用之间存储任何内容。但我现在没有测试这个。拨打电话的方式有多种,我认为有些会存储 cookie,有些则不会。

但无论如何:在您的场景中,确实没有理由在 Web 服务中使用会话:对于 Web 服务,只有一个客户端(Web 应用程序),因此如果需要,您也可以使用应用程序状态缓存数据什么的。

When the .Net application is calling the web service, it is the .Net web application that is the client and who owns the session. The session of the web service is - in the best case - specific to the .Net web application, not to the user with the browser, who was the client of the Web Application.

I think the default case is even that the session starts every time web service call is made (web service calls do not save cookies, which are required for session state), so it does not store anything between calls. But I did not test this now. There are several ways of making the call and I think some of them store cookies and some don't.

But in any case: In your scenario, there is really no reason to use session in the web services: For web services, there is only one client (the web app), so you could as well use Application state, if you need to cache data or something.

李不 2024-08-29 07:06:42

如果您或多或少要自动延长超时时间,为什么不一开始就将其设置得很高呢? KISS 可以让您省去在不需要的地方编写代码的麻烦。

If you're going to more or less automatically extend the timeout, why not just set it very high to begin with? K.I.S.S. and save yourself the hassle of writing code where you don't really need to.

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