asp.net – 有浏览器相当于IE的ClearAuthenticationCache?
|
我在这里有一些内部的.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)现在随机字符串凭证被浏览器接受和缓存。当他们访问另一个页面时,它将尝试使用它们,失败,然后提示正确的页面。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET C#5异步Web应用程序使用异步和等待
- iis-7 – 如何配置IIS 7(折扣asp.net)以指向应用程序子目录
- asp.net-mvc-3 – 解析器错误:服务器错误在’/’应用程序
- asp.net – IIS(动态和静态)缓存,OutPutCache和浏览器缓存之
- asp.net-mvc – 如何将MEF与ASP.NET MVC 4和ASP.NET Web AP
- asp.net-mvc-3 – 什么冒号(:)意味着在c#中定义一个类?
- “必须知道”.NET Architect / Lead的IIS功能
- asp.net-mvc – 如何添加到Azure会话Cookie HttpOnly和Secu
- asp.net-mvc-3 – ASP.Net MVC 3:在html.DropDownListFor中
- asp-classic – 如何检查VBScript中是否存在POST提交字段?
