私はかなり一貫しているように見えますが、ハッキーであり、それでも満足していない修正を思いつきました。
それでも動作します:-)
1)ログオフページにリダイレクトします
2)そのページでスクリプトを起動して、ダミーのクレデンシャル(jQueryのサンプル)を使用して別のページをajaxロードします。
$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)これで、ランダムな文字列のクレデンシャルが受け入れられ、代わりにブラウザによってキャッシュされました。彼らが別のページにアクセスすると、それらを使用しようとし、失敗してから、適切なページの入力を求めます。