2

私は、のようcontrollerなことをする権限属性を持っています。javascript 呼び出しでログイン アクションが成功した後、他のすべてのアクションは引き続きエラーを返します。私の例では、ログアウトアクションを使用して 401 を返し、私の問題につながります。loginlogout401 Unauthorized

行動

[HttpGet]
[AllowAnonymous]
[Mvc.ValidateAntiForgeryToken]
public bool Login(string param)
{
    var parameters = param.Split('/');
    var username = parameters[0];
    var password = parameters[1];

    if (WebSecurity.Login(username, password, true))
        return true;
    return false;
}

[HttpGet]
[Mvc.ValidateAntiForgeryToken]
public void Logout()
{
    WebSecurity.Logout();
}

アヤックス

public login(username: string, password: string): bool {
    var url = this.baseUrl + "Account/Login/" +
        encodeURIComponent(username) + "/" + encodeURIComponent(password);
    var xhr: JQueryXHR = $.ajax({
        type: "GET",
        url: url,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: false,
        cache: false
    });
    if (xhr.status == 200)
        if (xhr.responseText == "true")
            return true;
    return false;
}

public logout(): bool {
    var url = this.baseUrl + "Account/Logout/";
    var deferred: JQueryDeferred = $.Deferred();
    var xhr = $.ajax({
        type: "GET",
        url: url,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        cache: false,
        async: false
    });
    if (xhr.status == 200)
        return true;
    return false;
}
4

0 に答える 0