简体   繁体   English

在ajax调用中处理过期.NET Forms身份验证的最佳方法是什么?

[英]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.

相关问题 使用ASP.Net Forms身份验证的WCF服务-Cookie过期时$ .ajax()调用期间出错 - WCF service using ASP.Net Forms authentification - error during $.ajax() call when cookie is expired 强大的表单身份验证:这是最好的方法吗? - Robust Forms Authentication: Is this the best way? ASP.NET Ajax调用会话已过期 - ASP.NET Ajax Call Session Expired 在MVC3中处理登录/身份验证的最佳方法 - Best way to handle Login / Authentication in mvc3 如何在ASP.NET Web应用程序上使用表单身份验证最好地处理基于角色的权限? - How do I best handle role based permissions using Forms Authentication on my ASP.NET web application? 在MouseOver上处理ASP.NET Ajax模式的最佳方法-仅在请求时提取数据 - Best Way to Handle ASP.NET Ajax Modal on MouseOver - Only Pulling Data at Time of Request 表单身份验证过期后自动注销asp.net网站 - log out of asp.net site automatically when forms authentication has expired 请求的 ASP.NET 表单身份验证失败。 原因:提供的票已过期 - ASP.NET Forms Authentication failed for the request. Reason: The ticket supplied has expired .NET网站处理高流量的最佳方法 - Best way for .NET website to handle high traffic 如何在setInterval ajax Web服务调用中停止ASP.net表单身份验证/会话更新? - How do I stop ASP.net forms authentication / session from renewing in setInterval ajax web service call?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM