asp.net – 有浏览器相当于IE的ClearAuthenticationCache?
发布时间:2020-12-16 00:46:30 所属栏目:asp.Net 来源:网络整理
导读:我在这里有一些内部的.net Web应用程序,要求用户“注销”他们。我知道这可能在内联网应用程序上似乎有所作为,但是它仍然存在。 我们正在为Intranet应用程序使用Windows身份验证,因此我们使用基本身份验证与Active Directory绑定,并且使用.net表单身份验
我在这里有一些内部的.net Web应用程序,要求用户“注销”他们。我知道这可能在内联网应用程序上似乎有所作为,但是它仍然存在。
我们正在为Intranet应用程序使用Windows身份验证,因此我们使用基本身份验证与Active Directory绑定,并且使用.net表单身份验证时,凭证存储在浏览器缓存中,而不是Cookie。 在IE6中,您可以通过执行以下操作来利用他们创建的特殊JavaScript函数: document.execCommand("ClearAuthenticationCache","false") 然而,对于其他支持的浏览器(即目前的Firefox,但是我努力支持多浏览器),我只需向用户显示他们需要关闭浏览器以退出应用程序的消息。有效刷新应用程序缓存。 有人知道某些命令/黑客/ etc。我可以在其他浏览器中使用刷新认证缓存? 解决方法
我已经提出了一个看起来相当一致的修复程序,但是却是hacky和
I’m still not happy with it。
它工作虽然:-) 1)将其重定向到注销页面 2)在该页面上,ajax的脚本会使用虚拟凭据加载另一个页面(jQuery中的示例): $j.ajax({ url: '<%:Url.Action("LogOff401",new { id = random })%>',type: 'POST',username: '<%:random%>',password: '<%:random%>',success: function () { alert('logged off'); } }); 3)首次应该返回401(强制新的凭据被传递),然后只接受虚拟凭据(MVC中的样本): [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)现在随机字符串凭证被浏览器接受和缓存。当他们访问另一个页面时,它将尝试使用它们,失败,然后提示正确的页面。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读