2

Windows 認証を使用する MVC 4 アプリケーションがあります。私の現在の課題は、ユーザーにログアウト ボタンを提供する必要があることです。これは、ストレート Chrome、ストレート IE で達成できますが、Google Chrome Frame(GCF) をミックスに追加すると、問題が発生するようです。

GCFでIE9を使用しています。

AJAX リクエストを送信しようとすると、GCF ネットワーク トレースが次のように表示されます。

リクエスト:

GET http://103581:107674@linkToMySite/LogOff401?_=1369312905224 HTTP/1.1
Accept: */*
Referer: http://LinkToMySite
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36
Authorization: user:pass

残念ながら、応答は失敗します。Chrome 開発者ツールはそれを拾いますが、Fiddler がそれを認識しないため、IE がリクエストの送信をブロックしていると思います。私は途方に暮れており、これをバグとして Google に報告する必要があるかどうか、何日もトラブルシューティングを行ってきました。

これはクライアント側のログアウト コードです (ここから適応http://trac-hacks.org/wiki/TrueHttpLogoutPatch ) :

function LogMeOut(url) {
    try {
        document.execCommand("ClearAuthenticationCache");
        SendAJAXLogout(url);
    }
    catch(err){
        try {
            SendAJAXLogout(url);
        } catch(err) {
            log("Unable to log this user out.");
        }
    }
    window.location.href = url;
}

function SendAJAXLogout(url) {
    $.ajax(url, {
        username: GetRandomNumber(10000, 99999),
        password: GetRandomNumber(10000, 99999),
        beforeSend: function (req) {
            req.setRequestHeader('Authorization', "user:pass");
        },
        cache: false,

        error: function (jqXHR, textStatus, errorThrown) {
            //alert("Error: " + textStatus);
            log("I'm logged out now");
        }
    });
}

これは、他の場所で取得したサーバー側のアクション メソッドですが、リンクが見つかりません (これは書いていません)。

[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

0 に答える 0