[英]Best way to handle expired .NET Forms authentication coookie in an ajax call?
I'm developing a ASP.NET MVC app and I'm wondering which is the best way to handle an expired .NET Forms authentication cookie detected during an ajax call. 我正在开发一个ASP.NET MVC应用程序,我想知道哪个是处理在ajax调用期间检测到的过期.NET Forms身份验证cookie的最佳方法。
Do you think that packing the ajax response into a JsonResult containing info about the cookie validity is the best solution? 您是否认为将ajax响应打包到包含有关cookie有效性信息的JsonResult中是最佳解决方案?
我首选的方法是弹出一条消息说会话已经过期,然后重定向到登录页面,登录页面将在登录后恢复到当前页面。
One could get real fancy with this. 人们可以对此有所了解。 If AJAX on onError is invalid session, pop open a modal popup (lighbox form) with your login view wrapped inside.
如果onError上的AJAX是无效会话,则弹出一个模式弹出窗口(lighbox表单),其中包含您的登录视图。 Allow the user to login from the modal, then they do not lose any form data and were not redirected all over your site.
允许用户从模式登录,然后他们不会丢失任何表单数据,也不会在您的站点上重定向。 Most likely, the will need to attempt to repost thier data however.
最有可能的是,遗嘱需要尝试重新发布其数据。 Might take some doing, but in the end, I think it is more seamless for the end user.
可能会采取一些措施,但最后,我认为它对最终用户来说更加无缝。
PS - I am thinking Digg.com type login interface. PS - 我在想Digg.com类型的登录界面。 Click add comment, you get the modal popup.
点击添加评论,即可获得模态弹出窗口。
not sure which ajax framework you are using, but most (including asp.net ajax) handles server exceptions by letting you specify onError function. 不确定您使用的是哪个ajax框架,但大多数(包括asp.net ajax)通过让您指定onError函数来处理服务器异常。
Namespace.Object.Method( var1, var2, onSuccess, onError ) { .. } etc.. Namespace.Object.Method(var1,var2,onSuccess,onError){..}等。
if you let asp.net manage sessions, and as long as page in question is enabled for authenticated users only, the framework will throw invalid session exception when it has expired (i forget which exactly) 如果你让asp.net管理会话,并且只要为经过身份验证的用户启用了有问题的页面,框架将在它过期时抛出无效的会话异常(我忘记了哪个)
inside onError you can check for exception type, and re-direct to login page. 在onError中,您可以检查异常类型,并重定向到登录页面。 in fact, all you have to do is reload current page and .net will redirect it to login page for you.
事实上,您所要做的就是重新加载当前页面,.net会将其重定向到登录页面。 document.location.href = document.location.href;
document.location.href = document.location.href; (this will reload current page ignoring submitted form data if any)
(这将重新加载当前页面,忽略提交的表单数据,如果有的话)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.