只是尝试简单的身份验证工作,但在尝试登录时收到异常:
在数据库中播种:
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();
我错过了什么?
答案 0 :(得分:2)
看起来我错过了app.UseIdentity();
必须在app.UseMvc();