asp.net-mvc – 为什么UserManager.CreateIdentityAsync()正在寻
发布时间:2020-12-16 00:12:30 所属栏目:asp.Net 来源:网络整理
导读:我正在使用Identity2.0和MVC5 CodeFirst我已经扩展了IdentityUser和IdentityRole,如下所示: public class ApplicationUser : IdentityUser{ [Required] [StringLength(50)] public string FirstName { get; set; } [Required] [StringLength(50)] public st
我正在使用Identity2.0和MVC5 CodeFirst我已经扩展了IdentityUser和IdentityRole,如下所示:
public class ApplicationUser : IdentityUser { [Required] [StringLength(50)] public string FirstName { get; set; } [Required] [StringLength(50)] public string LastName { get; set; } } public class ApplicationRole : IdentityRole { [Required] [StringLength(50)] public string ProperName { get; set; } [Required] public string Description { get; set; } } public class MyAppDb : IdentityDbContext<ApplicationUser,ApplicationRole,string,IdentityUserLogin,IdentityUserRole,IdentityUserClaim> { public MyAppDb() : base("MyAppDb") { } } 注意MyAppDb继承自IdentityDbContext但我传递的是ApplicationRole而不是IdentityRole.我的ApplicationRole继承自IdentityRole,所以这应该不是问题. 但… 我的AccountController抛出了这个错误: The entity type IdentityRole is not part of the model for the current context. 在此代码中的UserManager.CreateIdentityAsync(…): private async Task SignInAsync(ApplicationUser user,bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user,DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent },identity); } 用户正在这里创建: var user = await UserManager.FindAsync(model.UserName,model.Password); if (user != null) { await SignInAsync(user,model.RememberMe); return RedirectToLocal(returnUrl); } 什么是“重大故障”? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – DropDownList SelectedIndex值未在AutoPostback
- 在ASP.net“正确”中实现OpenID – 会员或验证提供商?
- asp.net-mvc – 双值绑定问题
- asp.net – IIS错误 – HTTP错误500.24 – 内部服务器错误
- asp.net-web-api – 在运行时禁用ApiController
- asp.net-mvc – @ Html.ActionLink如何添加一个查询字符串
- Asp.net mvc 知多少(一)
- asp.net-mvc-4 – LinkedIn在MVC4中使用DotNetOpenAuth的完
- asp.net-mvc-3 – StringLength属性行为
- asp.net – scriptresource.axd 404错误在asp net 4应用程序
推荐文章
站长推荐
- 何时使用ASP.NET MVC与ASP.NET Web窗体?
- asp.net-mvc – System.Web.MVC.UpdateModel可以
- ASP.NET MVC中将数据从Controller传递到视图
- 将azure AD身份验证与asp.net核心身份个人帐户集
- ASP.NET MVC:将自定义属性放入选择列表中的选项
- asp.net-core – 实体框架核心以编程方式应用迁移
- asp.net-web-api – Web API 2是否可以通过编程方
- asp.net-mvc – Mac上是否有一个好的编辑器支持A
- 我可以在Asp.Net中的另一个页面中访问一个页面的
- ASP.NET C#在SQL Server数据库表中搜索
热点阅读