使用ajax在MVC 2中处理会话过期
我想检查会话是否过期。 所以我决定创建一个名为 IsServerExpired 的操作,并让它返回一个包含布尔值和重定向 url 的 json 对象。
所以java脚本函数将以指定的时间间隔对此操作执行ajax请求.. 我有一些基本问题..
1.如果我发送ajax请求,我认为这会刷新会话时间。因此,实际上,如果我使用此方法,会话将不会过期。我说得对吗?
如果刷新,我如何使用轮询检查会话过期
I want to check the session expired or not.
SO what i decided is Create an action called IsServerExpired and have it return a json object containing a boolean value, and the redirect url.
SO the java script function will do an ajax request to this action with specified time interval ..
I have some basic questions ..
1.If i send an ajax request ,i think that will refresh the session time . So in effect the session will not expire if i am using this method. am i right ?
If it refreshes how can i check session expire using polling
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您对 ASP.NET 会话和身份验证 cookie 感到困惑。我怀疑你在这里谈论的是身份验证 cookie 过期。如果您在 web.config 中将
slidingExpiration
设置为 true,那么轮询 AJAX 请求将更新超时,因此它们不适合。 Phil Haack 描述了一种非常优雅的方法来检测 AJAX 调用中的身份验证 cookie 过期 此博文。I think you are confusing between an ASP.NET session and the authentication cookie. I suspect that you are talking about the authentication cookie expiration here. If you have set
slidingExpiration
to true in your web.config then polling AJAX requests will renew the timeout so they are not suitable. Phil Haack described a very elegant way to detect authentication cookie expiration in AJAX calls in this blog post.有更简单的方法可以在会话过期后注销用户。
您可以将
SessionTimeout
保存在客户端的某个位置并运行客户端计时器,一旦计时器到达终点,就会重定向用户以注销 url。这是一个例子。这里的
Model
包含SessionTimeout
值。更用户友好的方式是显示弹出窗口,提示会话将在一分钟内过期(如果会话超时 15 分钟,则在 14 分钟后显示),以便用户能够刷新页面。并继续工作。
There is more simple approach to log out user once session expired.
You can save
SessionTimeout
somewhere on the client side and run client side timer, once timer reach end redirect user to log out url.Here is example.
Model
here containtsSessionTimeout
value.More user friendly way is to show popup that will say that session will be expired wihtin one minute(if session timeout 15 mins then show it after 14 mins), so user will be able refresh page. and continue work.