Asp.Net MVC 2 中会话超时时的确认
我想在会话超时还剩 2 分钟时提示用户。如果用户按是,它将刷新当前会话,而不会丢失表单数据;如果用户选择否,则会注销其会话。我想知道如何捕获剩余的两分钟以及如何刷新当前会话而不丢失表单数据。我使用 Asp.Net MVC 2 和 JQuery,还有一件事我没有使用表单身份验证
I want to prompt the user when 2minutes will left in session timeout. If user press Yes it refreshes its current session without losing the form data if user select No then it logout its session. I want to know how to capture that two minutes are remaining and how to refresh the current session without losing form data. Im using Asp.Net MVC 2 with JQuery, One more thing Im not using Form Authentication
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,每次请求后都会刷新会话。您可以在
Session.Timeout
上找到会话超时。您可以在母版页中执行以下操作:然后,如果您使用 AJAX,则需要在每次 AJAX 完成回调时重置超时:
很难获得 100% 的可靠性。您需要确保确认回调中的 AJAX 请求实际触及状态服务器,并且需要处理 AJAX 请求失败时发生的情况。即使您有此脚本,这些事情也可能导致您的会话过期。
硬币的另一面是这种情况会比必要时更频繁地出现。例如,如果您通过 javascript 将图像添加到 DOM,并且该图像的检索正在触及您的状态,则该请求不会重置 javascript 超时,尽管会话已刷新。
Well, the session is refreshed after each request. You can find the session timeout on
Session.Timeout
. You could do something like this in your masterpage:Then, you need to reset the timeout at every AJAX complete callback, if you're using AJAX:
It'll be difficult to get this 100% reliable. You need to make sure that the AJAX request in the confirm callback actually touches the state server, and you need to handle what happens when that AJAX request fails. Those are the things that could cause your session to expire even though you have this script.
The other side of the coin is where this will pop up more often than necessary. For instance, if you're adding an image to the DOM through javascript, and the retrieval of that image is touching your state, that request will not reset the javascript timeout, although the session has been refreshed.