简体   繁体   中英

Unable to sign-in because of Microsoft.AspNet.Identity.Application error

Just trying to get simple authentication working, but receive exception when trying to login:

Seeded the DB with:

user = new ApplicationUser
{
    FirstName = "John",
    LastName = "Smith",
    UserName = "jsmith",
    Email = "jsmith@gmail.com",
    EmailConfirmed = true,
    LockoutEnabled = false
};
var result = await _userManager.CreateAsync(user, "P@ssW4rd");

Logging in...

var b = await _securityManager.FindByEmailAsync(model.Username);
try
{
    var result = await _loginManager.PasswordSignInAsync(b.UserName, 
                        model.Password, false, lockoutOnFailure: false);
    if (result.Succeeded)
    {
        return RedirectToReturnUrl(returnUrl);
    }
}
catch (Exception e)
{
}     

The following exception is caught:

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

So then my configuration...

Startup.cs ConfigureServices

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddEntityFrameworkStores<AppDbContext>()
    .AddDefaultTokenProviders();

Startup.cs Configure

app.UseIdentity();

What did I miss?

Looks like I missed the fact that app.UseIdentity(); must go before app.UseMvc();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM