asp.net-mvc – UserManager.Create(用户,密码)thowing EntityValidat
发布时间:2020-05-23 20:21:46 所属栏目:asp.Net 来源:互联网
导读:有人知道为什么UserManager.Create(用户,密码);可能会抛出EntityValidationError,表示Id是必需的. 它可能与我的UserManager有关.设置如下: public class MyAppDb : IdentityDbContextApplicationUser, ApplicationRole, string, ApplicationUserLogin,
|
有人知道为什么UserManager.Create(用户,密码);可能会抛出EntityValidationError,表示Id是必需的. 它可能与我的UserManager有关.设置如下: public class MyAppDb : IdentityDbContext<ApplicationUser,ApplicationRole,string,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim>
{
public static MyAppDb Create()
{
return new MyAppDb();
}
public MyAppDb()
: base("MyAppDb")
{
}
}
public class ApplicationUserStore : UserStore<ApplicationUser,ApplicationUserClaim>
{
public ApplicationUserStore(MyAppDb context)
: base(context)
{
}
}
public class ApplicationUserManager : UserManager<ApplicationUser,string>
{
public ApplicationUserManager(IUserStore<ApplicationUser,string> store)
: base(store)
{
}
}
在这样的控制器中: public class AccountController : Controller
{
public AccountController()
: this(new ApplicationUserManager(new ApplicationUserStore(new MyAppDb())))
{
}
public AccountController(ApplicationUserManager userManager)
{
UserManager = userManager;
UserManager.PasswordValidator = (IIdentityValidator<string>)new MinimumLengthValidator(8);
UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager) { AllowOnlyAlphanumericUserNames = false,RequireUniqueEmail = true };
}
public ApplicationUserManager UserManager { get; private set; }
...
}
ApplicationUser,ApplicationUserRole和ApplicationUserClaim都分别从Identity类继承. 有人看错了吗?在创建没有Id问题的所有自定义Identity类之前,我能够注册用户(UserManager.Create()). 更新:似乎指定Key的字符串已破坏数据库上下文中自动生成的Key.这是我最好的猜测.它现在正在寻找我设置Id.我不想,我希望它在我在用户上创建自定义字段之前的工作方式. 解决方法看来指定字符串告诉UserStore您将提供Id.当我解决了以下问题 Is there a way to create a custom User and Role without specifying the TKey on IdenitityUser,IdentityRole,and IdentityDbContext?时,这个问题就消失了-要么- 只需给它一个像这样的ID:Guid.NewGuid().ToString() (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-core-mvc – ASP NET Core 2.0 appsettings.Develo
- asp.net-mvc – Elmah.MVC对Elmah.contrib.Mvc
- asp.net-mvc – .net MVC控制器动作方法的属性
- asp.net-mvc – 何时公开IEnumerable而不是ICollection?
- asp.net – 如何动态显示网站上的SVN修订版?
- asp.net – 在web-farm网站上将machineKey添加到web.config
- 十七点学完安全知识超级详细了解进程和病毒知识 转载
- asp.net – 应用程序域和应用程序池之间的区别?
- asp.net-web-api – 仅在第一个Web请求(WebAPI 2,OWIN 3,Ni
- asp.net – 使用回发解析.Net页面
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC中的Page.EnableSess
- ASP.NET TreeView和选择所选节点
- asp.net – 访问asp:从代码背后的内容
- asp.net-core – 如何在Visual Studio 2015 RC中
- 强制ASP.NET应用程序从bin而不是GAC加载程序集
- asp.net – 用JavaScript计算时间间隔
- asp.net – 使用sql server的Web应用程序中的审计
- asp.net-mvc – 数据注释真的是一个好主意验证吗
- asp.net – 控制器SessionStateBehavior是ReadOn
- asp.net-mvc – 使用TFS 2015 Build构建和部署We
热点阅读
