gpt4 book ai didi

c# - 使用 WsFederation 在 AspNetCore 2.1 中注销(注销)错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:38 26 4
gpt4 key购买 nike

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

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 中的代码片段

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

最佳答案

如错误所示,您使用以下代码注册了 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);

关于c# - 使用 WsFederation 在 AspNetCore 2.1 中注销(注销)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52992707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com