Determine how many ASP .NET MVC roles user has after login?
(Learning ASP .NET MVC 3).
How would I implement a method that would determine the number of ASP .NET roles the validated use开发者_StackOverflow中文版r belongs to?
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
//???? start
if(howManyRoles(mode.UserName) > 1)
{
//get user to pick desire role
}
//???? end
If you're using SqlRoleProvider than something like this:
public int howManyRoles()
{
var roleProvider = new SqlRoleProvider();
var roles = roleProvider.GetRolesForUser(User.Identity.Name);
return roles.Length;
}
精彩评论