开发者

Determine how many ASP .NET MVC roles user has after login?

开发者 https://www.devze.com 2023-02-14 11:14 出处:网络
(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?

(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;
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号