ADFS获取登录用户的所有角色

时间:2011-11-29 04:23:53

标签: c# asp.net adfs

我正在使用http://technet.microsoft.com/en-us/library/cc753987%28WS.10%29.aspx中提供的此示例应用程序 使用ADFS声明感知应用程序。 我的问题是如何获得用户使用ADFS的所有角色,上面的代码只有一个示例来检查使用User.IsInRole(角色)的角色。

3 个答案:

答案 0 :(得分:0)

要查看完整列表,您可以查看here 我还会指出你answer

答案 1 :(得分:0)

IClaimsPrincipal principal = (IClaimsPrincipal)this.Context.User;
IClaimsIdentity identity = principal.Identites[0];

var roles = identity.Claims
                .Where( c => c.ClaimType == ClaimTypes.Role )
                .Select( c => c.Value );

答案 2 :(得分:0)

参考How to: Access Claims in an ASP.NET Page

修改:要回答WIF的评论:

对于支持的操作系统:Windows 7,Windows Server 2008 R2,Windows Server 2008 Service Pack 2,Windows Vista Service Pack 2

  • Microsoft®Internet信息服务(IIS)7.0
  • Microsoft®.NETFramework 3.5

对于支持的操作系统:Windows Server 2003 Service Pack 2

  • Microsoft®Internet信息服务(IIS)6.0
  • Microsoft®.NETFramework 3.5