我在 ASP .NET Core 2.1 应用程序中注销(注销)时收到以下错误
没有为“联合”方案注册注销身份验证处理程序。注册的注销方案有:WsFederation、Cookies。您是否忘记调用 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);
}
如错误所示,您注册了WsFederation
and Cookies
代码如下:
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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)