i implemented custom role and membersip providers.
and i have question, when user get roles???
i have something like:
if (provider.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
}
that works.
But then, in some controller, i use:
if (!User.IsInRole("user"))
return RedirectToAction("Index", "Home");
and it always false, like user do not have any roles.
so finally, when user gets this roles, and where they are stored????
The
IsInRolemethod queries the role provider to determine if the currently logged in user has the role. When you create a new ASP.NET MVC application using the default template it uses a SQL role provider meaning that it stores the roles in the database. So when you create a new user you can assign him roles and when you useUser.IsInRoleit will query the database. Here’s a blog post which describes in more details.