【发布时间】:2019-05-05 14:58:54
【问题描述】:
我正在使用 asp.net mvc core 2.1 版本,在 ApplicationUser 类中添加属性时收到这两个错误 我在这段代码上收到错误:
var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
我正在尝试从过去 3 天开始修复它错误是:
“UserManager”不包含“CreateIdentityAsync”的定义,并且找不到接受“UserManager”类型的第一个参数的可访问扩展方法“CreateIdentityAsync”(您是否缺少 using 指令或程序集引用?)
“当前上下文中不存在名称‘DefaultAuthenticationTypes’”
我的班级如下
public class ApplicationUser:IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public string FullName { set; get; }
public string MobileNumber { get; set; }
public int CountryId { get; set; }
public int StateId { get; set; }
public int CityId { set; get; }
public string Address { get; set; }
public string ShippingAddress { get; set; }
}
【问题讨论】:
-
CreateIdentityAsync是一种 ASP.NET MVC 5 方法,它在 ASP.NET Core 中不存在。我认为SignInManager<ApplicationUser>.CreateUserPrincipalAsync会做你想做的事。 -
我想在我的 AspNetUser 表中添加一些属性。但我陷入了这个错误。
-
我有同样的问题,将这个错误停留了 3 天 - “当前上下文中不存在名称 'DefaultAuthenticationTypes'”。请有人帮忙。
标签: c# asp.net-core asp.net-core-mvc asp.net-identity