由于Microsoft.AspNet.Identity.Application错误,无法登录

时间:2016-03-24 16:32:19

标签: c# asp.net-mvc asp.net-core-mvc asp.net-identity-3

只是尝试简单的身份验证工作,但在尝试登录时收到异常:

在数据库中播种:

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");

登录...

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)
{
}     

发现以下异常:

  

没有配置身份验证处理程序来处理该方案:   Microsoft.AspNet.Identity.Application

那么我的配置......

Startup.cs ConfigureServices

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

Startup.cs Configure

app.UseIdentity();

我错过了什么?

1 个答案:

答案 0 :(得分:2)

看起来我错过了app.UseIdentity();必须在app.UseMvc();

之前去的事实