ASP.Net中的客户端会话超时重定向 [英] Client-side session timeout redirect in ASP.Net

查看:98
本文介绍了ASP.Net中的客户端会话超时重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一种方法,可以在用户会话由于不活动而过期时自动将其重定向到Timeout.aspx.我的应用程序使用表单身份验证,并且在很大程度上依赖于同一个aspx页面中的更新面板来进行用户交互,因此我不想在页面级计时器到期后直接重定向.出于相同的原因,我不能使用'< meta http-equiv ="refresh"/>'

I want to build a way to automatically redirect users to Timeout.aspx when their session expires due to inactivity. My application uses forms authentication and relies heavily on update panels within the same aspx page for user interaction, so I don't want to simply redirect after a page-level timer expires. For the same reason, I can't use '<meta http-equiv="refresh"/>'

我想做的是使用名为IsSessionTimedOut()的方法创建一个简单的Ajax Web服务,该方法仅返回一个布尔值.我将使用一个JavaScript计时器来定期调用该方法,如果该方法返回true,则将其重定向到Timeout.aspx.但是,我不想调用此方法来重置会话超时计时器,否则会话将永远不会因服务调用而超时.有没有一种干净的方法来避免捕获22?希望到目前为止,有一个简单的解决方案使我望而却步.

What I want to do is create a simple ajax web service with a method called IsSessionTimedOut(), that simply returns a boolean. I will use a javascript timer to periodically call the method, and if it returns true, then redirect to Timeout.aspx. However, I don't want calling this method to reset the session timeout timer, or the session would never time out because of the service call. Is there a clean way to avoid this catch-22? Hopefully there is an easy solution that has so far eluded me.

推荐答案

问题的症结在于,在AJAX应用程序中,要提供可靠的用户体验,您必须使用大量的代码检查每个调用的状态,以使客户端脚本混乱并确定故障是否是由于会话/票证过时导致的.通过主动的方法,可以大大简化客户端脚本,同时提供更好的用户体验.

the crux of the problem is that in AJAX apps, to provide a robust user experience you must clutter your client script with reams of code checking the status of every call and determining if a failure is due to a stale session/ticket. With a proactive approach your client script can be dramatically simplified while at the same time providing a much better user experience.

我专门针对此问题建立了解决方案.

I have built a solution for this problem specifically.

它允许交互式会话和表单票证生命周期审核, 而不会增加会话或票证.

It allows interactive session and forms ticket lifetime auditing without bumping the session or ticket.

多个浏览器/选项卡都没问题.

Multiple browsers/tabs are no problem.

忘记防晒霜;记住:做Ajax时要主动-您应该放弃会话,会话不应该放弃您;-)

Forget the sunscreen; Remember: When doing Ajax, be proactive - You should abandon a session, a session should not abandon you ;-)

AsynchronousSessionAuditor 1.0

这篇关于ASP.Net中的客户端会话超时重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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