I have created several roles for me to do an access control. So I want to know how to call the admin role so I can pass in an if, type example that I'll put below in my _layout:
@if ("Aqui que eu preciso saber como chamar a role admin")
{
<li>@Html.ActionLink("Início", "Index", "Home")</li>
<li>@Html.ActionLink("Sobre", "About", "Home")</li>
<li>@Html.ActionLink("Contato", "Contact", "Home")</li>
}
else
{
<li>@Html.ActionLink("Sobre", "About", "Home")</li>
}
Here's how I created the role in my startup file:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
createRolesandUsers();
}
// In this method we will create default User roles and Admin user for login
private void createRolesandUsers()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
// In Startup iam creating first Admin Role and creating a default Admin User
if (!roleManager.RoleExists("Admin"))
{
// criando a role do usuario Admin
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = "Admin";
roleManager.Create(role);
//Aqui estou criando o usuario que terá o acesso completo
var user = new ApplicationUser();
user.UserName = "ebase";
user.Email = "[email protected]";
string userPWD = "123456";
var chkUser = UserManager.Create(user, userPWD);
//Add default User to Role Admin
if (chkUser.Succeeded)
{
var result1 = UserManager.AddToRole(user.Id, "Admin");
}
}