asp.net – 有浏览器相当于IE的ClearAuthenticationCache?

前端之家收集整理的这篇文章主要介绍了asp.net – 有浏览器相当于IE的ClearAuthenticationCache?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这里有一些内部的.net Web应用程序,要求用户“注销”他们。我知道这可能在内联网应用程序上似乎有所作为,但是它仍然存在。

我们正在为Intranet应用程序使用Windows身份验证,因此我们使用基本身份验证与Active Directory绑定,并且使用.net表单身份验证时,凭证存储在浏览器缓存中,而不是Cookie。

在IE6中,您可以通过执行以下操作来利用他们创建的特殊JavaScript函数

@H_502_6@document.execCommand("ClearAuthenticationCache","false")

然而,对于其他支持的浏览器(即目前的Firefox,但是我努力支持多浏览器),我只需向用户显示他们需要关闭浏览器以退出应用程序的消息。有效刷新应用程序缓存。

有人知道某些命令/黑客/ etc。我可以在其他浏览器中使用刷新认证缓存?

解决方法

我已经提出了一个看起来相当一致的修复程序,但是却是hacky和 I’m still not happy with it

它工作虽然:-)

1)将其重定向到注销页面

2)在该页面上,ajax的脚本会使用虚拟凭据加载另一个页面(jQuery中的示例):

@H_502_6@$j.ajax({ url: '<%:Url.Action("logoff401",new { id = random })%>',type: 'POST',username: '<%:random%>',password: '<%:random%>',success: function () { alert('logged off'); } });

3)首次应该返回401(强制新的凭据被传递),然后只接受虚拟凭据(MVC中的样本):

@H_502_6@[AcceptVerbs(HttpVerbs.Post)] public ActionResult logoff401(string id) { // if we've been passed HTTP authorisation string httpAuth = this.Request.Headers["Authorization"]; if (!string.IsNullOrEmpty(httpAuth) && httpAuth.StartsWith("basic",StringComparison.OrdinalIgnoreCase)) { // build the string we expect - don't allow regular users to pass byte[] enc = Encoding.UTF8.GetBytes(id + ':' + id); string expected = "basic " + Convert.ToBase64String(enc); if (string.Equals(httpAuth,expected,StringComparison.OrdinalIgnoreCase)) { return Content("You are logged out."); } } // return a request for an HTTP basic auth token,this will cause XmlHttp to pass the new header this.Response.StatusCode = 401; this.Response.StatusDescription = "Unauthorized"; this.Response.AppendHeader("WWW-Authenticate","basic realm=\"My Realm\""); return Content("Force AJAX component to sent header"); }

4)现在随机字符串凭证被浏览器接受和缓存。当他们访问另一个页面时,它将尝试使用它们,失败,然后提示正确的页面

猜你在找的asp.Net相关文章