使用ASP.NET GenericHandlers当ASP.NET管理会话超时 [英] Managing Session Timeouts in ASP.NET when using ASP.NET GenericHandlers

查看:120
本文介绍了使用ASP.NET GenericHandlers当ASP.NET管理会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我使用jQuery作为在客户端框架的Web应用程序。现在大部分的网页是功能通过使用AJAX,并通过使用通用处理程序(.ashx的)的装置传送到所述服务器的装置。

For example I have a web application using jQuery as a framework on the client side. Now most of the pages are functional by means of using AJAX and communicate to the server by means of using Generic Handlers (.ashx).

现在我有,我问这个,看看有什么是处理这些请求时,我的用户会话到期的最佳解决方案的问题。

Now I have a problem that I am asking this to see what is the best solution for handling these request when my user session expires.

例如,用户登录后,留下了自己的浏览器进行15分钟,然后他pressed一个按钮,这将创建一个请求处理程序,现在从服务器端,当我尝试明明读会话变量这将是空的(会话过期)。什么是将用户重定向回到登录页面的最佳方式。

For example, a user logged in, left his browser for 15 minutes and then he pressed a button that this will create a request to the handler, now from the server side when I try to read a session variable obviously it will be empty (session expired). What is the best way to redirect the user back to the login page.

推荐答案

我们针对这种情况通过一个稍微不同的方法。而不是试图让所有的jQuery的调用处理这种错误情况,我们已经实现了使用JavaScript客户端上的并行超时系统。 ASP.NET会话前一分钟将超时,我们就弹出一个对话框上的浏览器向用户发出警告:你已经没有什么活动,并即将被注销。点击这里继续登录。我们包括一个小倒计时对话框也研究。如果他们点击保持登录状态,我们发送另一个jQuery的调用服务器复位会话超时。

We address this situation by a slightly different approach. Instead of trying to make all the jQuery calls deal with this kind of error condition, we have implemented a parallel timeout system on the client using javascript. A minute before the ASP.NET Session would time out, we pop up a dialog on the browser to warn the user "You have been inactive and are about to be logged out. Click here to remain logged in." We included a little countdown in the dialog also. If they click to stay logged in, we send another jQuery call to the server to reset the session timeout.

因此​​,除非用户已禁用JavaScript(在这种情况下,应用程序不反正工作),没有一种可能性,即我们做一个jQuery的电话后,ASP.NET会话超时。

So, unless the user has javascript disabled (in which case, the app doesn't work anyway), there is not a possibility that we make a jQuery call after the ASP.NET session has timed out.

这篇关于使用ASP.NET GenericHandlers当ASP.NET管理会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆