Hello, I am trying to use user roles in a new Visual Studio 2013, ASP.NET Web Application (webforms).
Here is how I create a role and add the currently logged in user to it:
public class RoleManager : RoleManager<IdentityRole>
{
public RoleManager()
: base(new RoleStore<IdentityRole>(new ApplicationDbContext()))
{
}
}
protected void btnMakeAdmin_Click(object sender, EventArgs e)
{
const string ROLE_NAME= "Admin";
var roleManager = new RoleManager();
if (!roleManager.RoleExists(ROLE_NAME))
{
var roleresult = roleManager.Create(new IdentityRole(ROLE_NAME));
if (!roleresult.Succeeded) throw new Exception(String.Format("Unable to create a new role with the name {0}",ROLE_NAME));
}
var manag ...
Go to the complete details ...