ASP .NET MVC 4:WebSecurity.CreateUserAndAccount如何设置User
发布时间:2020-12-16 07:28:27 所属栏目:asp.Net 来源:网络整理
导读:我想在Configuration.cs中移动数据库表和数据(用户,角色e.t.c.中的用户)的初始化,如本文所述: http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-codefirst-and-custom-user-properti
我想在Configuration.cs中移动数据库表和数据(用户,角色e.t.c.中的用户)的初始化,如本文所述:
http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-codefirst-and-custom-user-properties/
但我有一个问题:是否可以设置添加用户的UserId?我的意思是,我可以添加5个用户,并且,我认为他们应该得到1-2-3-4-5 Ids,但我可以控制它并设置他们的Ids手册吗? 现在初始化看起来像: if (!WebSecurity.UserExists("elena")) WebSecurity.CreateUserAndAccount("elena","password"); 解决方法
是的,您可以通过传入要设置的属性来执行此操作.例如:
WebSecurity.CreateUserAndAccount("elena","password",new { UserId = 1 }); 当然,您需要确保UserId列未设置为标识列,并且您必须更改UsersContext架构以添加它. [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int UserId { get; set; } public string UserName { get; set; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET CAPTCHA实现
- asp.net-mvc – Owin自主和ASP .Net MVC
- asp.net-mvc – 为什么Visual Studio不会在发布中移动某些文
- 如何配置ASP.NET MVC项目以使用Boo
- 如何动态地从ASP.NET MVC控制器获取数据到jQuery?
- asp.net-mvc – System.Web.Optimization.Bundle与WebEssen
- asp.net-mvc – 在Razor VB.net中使用MVC无法按预期工作
- asp.net-mvc – 在mvc 5和web api 2之间共享owin cookie身份
- asp.net-mvc – “添加ASP.Net文件夹”未启用
- asp.net – 自动插入HTML属性的双引号
推荐文章
站长推荐
- Asp.net MVC使用EasyNetQ操作RabbitMQ
- asp.net-mvc – 在同一个视图文件夹中的RenderPa
- asp.net-web-api – 在WebApi2项目中使用CacheOu
- asp.net-mvc – AuthorizeAttribute对象的生命周
- asp.net-mvc – 在需要时在CQRS中提供同步行为?
- asp.net – System.Diagnostics.Process.Start不
- asp.net-core – db ASP.NET Core中的临时保存密
- 如何在ASP.NET中运行.py(Python)文件?
- 从asp.net中的gridview获取已检查的行
- ASP.NET Cookieless Forms在登录页面被加入书签时
热点阅读