Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No authentication handler is configured to handle the scheme: Microsoft.AspNet.Identity.Application

I am using ASP.NET Core with ASP.NET Identity and have the following:

User user = await _userManager.FindByEmailAsync(myEmail);

SignInResult result = await _signInManager.PasswordSignInAsync(user, myPassword, true, false);

I get a user but when I try to sign in the user I get the error:

[Error] An unhandled exception has occurred while executing the request

System.InvalidOperationException: No authentication handler is configured to handle the scheme: Microsoft.AspNet.Identity.Application

On web project Startup file I have:

public void Configure(IApplicationBuilder applicationBuilder, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory) {

  // Other configuration code lines

  applicationBuilder.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());

  applicationBuilder.UseIdentity();

} // Configure

public void ConfigureServices(IServiceCollection services) {

  // Other configuration code lines

  services
    .AddIdentity<User, Role>()
    .AddEntityFrameworkStores<Context, Int32>()
    .AddDefaultTokenProviders();
}

I have no idea what is wrong. I tried to change the configuration and I always get the same error ...

Any idea?

like image 601
Miguel Moura Avatar asked Mar 13 '23 21:03

Miguel Moura


1 Answers

applicationBuilder.UseIdentity(); 

is what should configure the cookie middleware, make sure that line is called before calling

applicationBuilder.UseMvc()

authentication must be configured before mvc

like image 75
Joe Audette Avatar answered Apr 28 '23 04:04

Joe Audette