1

(Learning ASP .NET MVC 3)。確定用戶登錄後有多少個ASP .NET MVC角色?

我該如何實現一個方法來確定驗證用戶所屬的ASP .NET角色的數量?

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 

回答

1

如果您使用SqlRoleProvider比是這樣的:

 public int howManyRoles() 
     { 
      var roleProvider = new SqlRoleProvider(); 
      var roles = roleProvider.GetRolesForUser(User.Identity.Name); 
      return roles.Length; 
     }