c# - 带有 WsFederation 的 AspNetCore 2.1 中的 SignOut (LogOut) 错误
问题描述
在 ASP .NET Core 2.1 应用程序中注销(注销)时出现以下错误
没有为方案“Federation”注册注销身份验证处理程序。注册的注销方案是: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
并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);
推荐阅读
- javascript - Selenium 点击播放用 Viedogular 包装的电影
- c - 如何将数组结构传递给函数
- java - com.sun.net.ssl.internal.Provider:tools:jar 的“dependencies.dependency.version”缺失
- office-js - 从 Excel 加载项创建新电子邮件
- kotlin - Kotlin 可迭代
- reactjs - 为什么在路由级别应用拆分仍然需要整个 bundle.js 文件?
- node.js - 猫鼬没有带来任何结果
- javascript - 使用过滤按最近的地理位置对数据进行排序
- c# - C# OAuth Jira 连接
- symfony - 更新覆盖模板后 FOSUserBundle 不起作用