开发者

Is there an existing solution to AJAX timeouts with ASP.NET MVC and jQuery?

You are using ASP.NET MVC with jQuery. You make a lot of AJAX calls. You want to notify the user if they click something and the session has timed out. Does anyone have a good existing solution to this that also inc开发者_开发知识库ludes notifying the user of timeout after initiating an AJAX request?

(There are known solutions for non-AJAX ASP.NET apps that involve detecting the timeout in Global.asax and redirecting to a specific page. Redirecting the AJAX request, however, is problematic because the user either won't see it, or will see it in the wrong context.)

This is something almost every application needs so I just want to make sure I don't reinvent the wheel. Thanks!


Here's what I do: when my server detects a session timeout, it responds with the reauthentication page, and it also sets a special header in the response. For Ajax, I just have my handler look for that header, and if it sees it it forces the surrounding page (i.e., location.href or whatever) to reload (with an extra "nonce" parameter to make sure it bypasses the browser cache).

Note that my solution isn't specifically an ASP.NET thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜