MOss213获得用户登录名

因SharePoint2013默认使用claims based authentication,所以其帐号会是i:0#.w|/domain name这样的格式,如何去掉前面的内容,只保留登录帐号呢?

参见https://sharepoint.stackexchange.com/questions/113215/problem-with-i0-w-domain-name的内容,使用如下方法即可:

private static string GetSimpleLoginName(SPUser user)
{
var username = "";
var claimsManager = SPClaimProviderManager.Local;

if (claimsManager != null)
{
if (SPClaimProviderManager.IsEncodedClaim(user.LoginName))
username = claimsManager.DecodeClaim(user.LoginName).Value;
else
username = user.LoginName;
}
return username.ToLower().Replace("hi-p\\", "");

}

需添加using Microsoft.SharePoint.Administration.Claims;的引用。

posted @ 2017-05-26 13:43  邑尘  阅读(145)  评论(0编辑  收藏  举报