【问题标题】:SignOut (LogOut) Error in AspNetCore 2.1 with WsFederation带有 WsFederation 的 AspNetCore 2.1 中的 SignOut (LogOut) 错误
【发布时间】:2018-10-26 14:50:24
【问题描述】:

在 ASP .NET Core 2.1 应用程序中注销(注销)时出现以下错误

没有为“Federation”方案注册注销身份验证处理程序。注册的注销方案是:WsFederation、Cookies。你忘记调用 AddAuthentication().AddCookies("Federation",...)

这是我的 Startup.cs 中的代码 sn-p

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultScheme =
                    CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultSignInScheme = 
                    CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = 
                    WsFederationDefaults.AuthenticationScheme;
        })
        .AddWsFederation(options =>
        {
            options.Wtrealm = this._wtrealm;
            options.MetadataAddress = this._metadataAddress;
        })
        .AddCookie();

}

这是SignOut方法的代码

    public IActionResult SignOut()      
    {
        foreach (var key in this.HttpContext.Request.Cookies.Keys)
        {
            this.HttpContext.Response.Cookies.Delete(key);

            // this.HttpContext.Response.Cookies.Append(key, 
            //                       string.Empty, 
            //                       new CookieOptions() { 
            //                             Expires = DateTime.Now.AddDays(-1) 
            //                       });
        }

        return this.SignOut(
             new  Microsoft.AspNetCore.Authentication.AuthenticationProperties 
             {
                  RedirectUri = this.GetReturnUrl() 
             },
             CookieAuthenticationDefaults.AuthenticationScheme,
             WsFederationAuthenticationDefaults.AuthenticationType);
    }

【问题讨论】:

    标签: c# .net asp.net-core ws-federation


    【解决方案1】:

    如错误所示,您使用以下代码注册了WsFederationCookies

    services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultScheme =
                    CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultSignInScheme = 
                    CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = 
                    WsFederationDefaults.AuthenticationScheme;
        })
        .AddWsFederation(options =>
        {
            options.Wtrealm = this._wtrealm;
            options.MetadataAddress = this._metadataAddress;
        })
    

    但是,您正在注销WsFederationAuthenticationDefaults.AuthenticationType,即Federation。您应该退出 WsFederationDefaults.AuthenticationScheme 而不是 WsFederationAuthenticationDefaults.AuthenticationType

    试试下面的代码:

    return this.SignOut(
             new  Microsoft.AspNetCore.Authentication.AuthenticationProperties 
             {
                  RedirectUri = this.GetReturnUrl() 
             },
             CookieAuthenticationDefaults.AuthenticationScheme,
             WsFederationDefaults.AuthenticationScheme);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多