按照旧的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
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?}");
});
}