获取当前用户的角色 [英] get current user's role

查看:122
本文介绍了获取当前用户的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法得到明确的角色,用户在我的控制器属于?这是假定使用ASP.NET成员身份和角色提供。 IsInRole不工作 - 我需要真正获得他们在角色的名称

Is there any way to get the explicit role that a user belongs to in my controller? This assumes using ASP.NET Membership and Role Providers. "IsInRole" doesn't work - I need to actually get the name of the role they are in.

推荐答案

您可以从<一个角色列表href=\"http://msdn.microsoft.com/en-us/library/system.web.security.roleprincipal.getroles%28VS.80%29.aspx\">GetRoles方法。 (从链接)

You can get a list of Roles from the GetRoles method. (From the link)

  string[] rolesArray;

  public void Page_Load()
  {
       RolePrincipal r = (RolePrincipal)User;
       rolesArray = r.GetRoles();
       ...//extra code
  }

这篇关于获取当前用户的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆