2015-09-04 123 views
-2

如何在空的mvc 5项目中添加角色?如何在mvc 5中添加角色?

我在谷歌搜索,但我没有找到项目的教程。

有人可以给我一个指南的链接或帮助我吗?

+0

http://typecastexception.com/post/2014/06/22/ASPNET-Identity-20-Customizing-Users-and-Roles.aspx –

回答

0

这样:

var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext())); 
if (!roleManager.RoleExists("RoleName")) 
{ 
     var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); 
     role.Name = "RoleName"; 
     roleManager.Create(role); 
} 
相关问题