使用Idenity按角色保护ASp.NET文件夹

时间:2014-04-01 20:26:20

标签: asp.net asp.net-identity

我们正在使用最新的ASP.NET,我们已经购买并扩展了新的ASP.NET身份系统。我现在尝试使用它来保护通过角色访问ASP.NET文件夹。我们扩展的IdentityModel是:

public class ApplicationUser : IdentityUser
    {
        public string CompanyName { get; set; }
        public string emailAddress { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string RegistrationCode { get; set; }
        public string skin { get; set; }
        public string ConfirmationToken { get; set; }
        public bool IsConfirmed { get; set; }
        public DateTime created { get; set; }

    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }
    }

我一直在使用UserManager来创建用户。如何使用Identity创建角色?是这样的(来自SO post

RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new MyDbContext()));
var roleresult = RoleManager.Create(new IdentityRole(roleName));

我将把这些代码放在哪里以及从哪里调用它?我想做一些像过去常常做的事情:

<location path="~/SavAdmin">
    <system.web>
      <authorization>
        <allow roles="Savitas Admin"/>
       <deny users="?" />
      </authorization>

0 个答案:

没有答案