如何使用ADFS获得用户的其他声明? [英] How do I get other claims of the user using ADFS?
本文介绍了如何使用ADFS获得用户的其他声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够使用ADFS验证用户身份,并成功使用以下语句获取用户别名。自一段时间以来,我一直在寻找一种方法来获取经过身份验证的用户的其他声明,例如电子邮件,姓名,角色,用户名等。
I am able to authenticate the user using ADFS and succeded in getting the user alias using the below statement. Since some time, i am looking for a way in getting the other claims of the authenticated user, like email, name, roles, username etc.
对此的任何帮助都会
字符串别名=((MicrosoftAdfsProxyRP.MicrosoftPrincipal)HttpContext.Current.User).Alias;
string alias = ((MicrosoftAdfsProxyRP.MicrosoftPrincipal)HttpContext.Current.User).Alias;
Response.Write(别名);
Response.Write (alias);
推荐答案
如果链接消失,则密钥为:
Just in case the link disappears, the key is:
void Page_Load(object sender, EventArgs e)
{
// Cast the Thread.CurrentPrincipal
IClaimsPrincipal icp = Thread.CurrentPrincipal as IClaimsPrincipal;
// Access IClaimsIdentity which contains claims
IClaimsIdentity claimsIdentity = (IClaimsIdentity)icp.Identity;
// Access claims
foreach(Claim claim in claimsIdentity.Claims)
{
Response.Write(claim.ClaimType) + "<BR>";
Response.Write(claim.Value) + "<BR>";
Response.Write(claim.ValueType) + "<BR>";
}
}
这篇关于如何使用ADFS获得用户的其他声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文