2015-09-04 122 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); 
} 
相關問題