带有WsFederation的AspNetCore 2.1中的注销(注销)错误 [英] SignOut (LogOut) Error in AspNetCore 2.1 with WsFederation

查看:105
本文介绍了带有WsFederation的AspNetCore 2.1中的注销(注销)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting following error while logging out (signing out) in ASP .NET Core 2.1 application

未为方案联合身份"注册任何注销身份验证处理程序.注册的注销方案是:WsFederation,Cookie.您是否忘了打电话给AddAuthentication().AddCookies("Federation",...)

No sign-out authentication handler is registered for the scheme 'Federation'. The registered sign-out schemes are: WsFederation, Cookies. Did you forget to call AddAuthentication().AddCookies("Federation",...)

这是我的Startup.cs中的代码段

Here is a code snippet in my Startup.cs

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方法中的代码

Here is a code from SignOut method

    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);
    }

推荐答案

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

As the error indicates, you registered WsFederation and Cookies with code below:

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 .

But, you are signout WsFederationAuthenticationDefaults.AuthenticationType which is Federation. You should signout WsFederationDefaults.AuthenticationScheme instead of WsFederationAuthenticationDefaults.AuthenticationType.

请尝试以下代码:

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

这篇关于带有WsFederation的AspNetCore 2.1中的注销(注销)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆