1

We are using the latest ASP.NET and we have bought into and extended the new ASP.NET Identity system. I am trying to now use it to secure access to ASP.NET folder by Role. Our IdentityModel as extended is:

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")
        {
        }
    }

I have been working with the UserManager to create users. How do I create Roles with Identity? Is it like this (from this SO post:

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

Where would I put such code and where would I call it from? I want to do something like what used to be done with:

<location path="~/SavAdmin">
    <system.web>
      <authorization>
        <allow roles="Savitas Admin"/>
       <deny users="?" />
      </authorization>
Community
  • 1
  • 1
user2471435
  • 1,644
  • 7
  • 35
  • 62
  • Is this Webforms or MVC and what type of content is in the folder (downloads, webpages etc). – Erik Philips Apr 01 '14 at 20:29
  • Its WebForms and the content in the folder is Admin WebForms that are supposed to be available only to the users with the Role "Savitas Admin" – user2471435 Apr 01 '14 at 20:32
  • You can create Roles as you mentioned in this post and protect the folders so only users in a certain role can access that folder – pranav rastogi Apr 07 '14 at 17:22

0 Answers0