问题描述
在ASP .NET Core 2.1应用程序中注销(注销)时出现以下错误
I am getting following error while logging out (signing out) in ASP .NET Core 2.1 application
这是我的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中的注销(注销)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!