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>