【发布时间】:2020-03-18 15:37:00
【问题描述】:
在将我的网站从 .NET Core 2.2 迁移到 3.1.1 后,我的 api 端点突然开始尝试将我的 api 请求重定向到默认登录页面 (/Account/Login?ReturnUrl=,我什至在我的任何路由中都没有)。
我的 api 正在使用 JWT 承载身份验证方案,带有 JWT 挑战方案,但仍然发生了重定向。
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
我终于找到了解决问题的方法,但我不知道为什么它确实有帮助。
最初我将服务设置为:
services
.AddIdentity<IdentityUser, IdentityRole>()
.AddSignInManager()
.AddEntityFrameworkStores<CleWebToolsIdentityDbContext>();
但这做了重定向。
最终解决我的问题是将它们设置为:
services
.AddIdentityCore<IdentityUser>()
.AddRoles<IdentityRole>()
.AddSignInManager()
.AddEntityFrameworkStores<CleWebToolsIdentityDbContext>();
谁能告诉我这是怎么回事?
即使挑战方案应该是 JWT,AddIdentity 方法如何导致重定向?
【问题讨论】:
标签: c# authentication .net-core asp.net-core-identity