C# asp.net核心未注册任何注销身份验证处理程序
遵循较旧的asp.net教程,并尝试使用asp.net core来代替。我调试我的应用程序并转到登录链接,我遇到了这个错误。有人能帮忙解决吗C# asp.net核心未注册任何注销身份验证处理程序,c#,asp.net-core,C#,Asp.net Core,遵循较旧的asp.net教程,并尝试使用asp.net core来代替。我调试我的应用程序并转到登录链接,我遇到了这个错误。有人能帮忙解决吗 An unhandled exception occurred while processing the request. InvalidOperationException: No sign-out authentication handlers are registered. Did you forget to call
An unhandled exception occurred while processing the request.
InvalidOperationException: No sign-out authentication handlers are
registered. Did you forget to call
AddAuthentication().AddCookies("Identity.External",...)
Microsoft.AspNetCore.Authentication.AuthenticationService.SignOutAsync(HttpContext context, string scheme, AuthenticationProperties properties)
此处代码中出现错误:
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
在这个街区的中间
ModelState.AddModelError(string.Empty, ErrorMessage);
}
returnUrl = returnUrl ?? Url.Content("~/");
// Clear the existing external cookie to ensure a clean login process
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
ReturnUrl = returnUrl;
}
Startup.cs如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddDbContext<GigHubContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("GigHubContextConnection")));
services.AddIdentityCore<GigHubUser>()
.AddEntityFrameworkStores<GigHubContext>()
.AddDefaultTokenProviders()
.AddDefaultUI();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
UserManager<GigHubUser> userManager)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//gigHubContext.Database.EnsureDeleted();
//gigHubContext.Database.Migrate();
// add db lookups
//DbDataInitializer.SeedGenres(gigHubContext);
//DbDataInitializer.SeedUsers(userManager);
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
public void配置服务(IServiceCollection服务)
{
配置(选项=>
{
//此lambda确定给定请求是否需要非必要cookie的用户同意。
options.checkApprovered=context=>true;
options.MinimumSameSitePolicy=SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“GigHubContextConnection”);
services.AddIdentityCore()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders()
.AddDefaultUI();
}
//此方法由运行时调用。使用此方法配置HTTP请求管道。
公共无效配置(
IApplicationBuilder应用程序,
IHostingEnvironment环境,
用户管理器(用户管理器)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//gigHubContext.Database.EnsureDeleted();
//gigHubContext.Database.Migrate();
//添加数据库查找
//种子类型(gigHubContext);
//DbDataInitializer.SeedUsers(userManager);
}
其他的
{
app.UseExceptionHandler(“/Home/Error”);
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseMvc(路由=>
{
routes.MapRoute(
名称:“默认”,
模板:“{controller=Home}/{action=Index}/{id?}”);
});
}
这是因为您使用的是AddIdentityCore
,而不是AddIdentity
或AddDefaultIdentity
。你有这样做的具体要求吗?如果没有,只需使用services.AddDefaultIdentity().AddEntityFrameworkStores()
在异常中说,将.AddCookies(“Identity.External”,…)
添加到您的UseAuthentication()
调用中Configure@KirkLarkin我没有这样的具体要求。AddDefaultIdentity似乎起到了作用!谢谢