MOss213得到用戶登陸名

因SharePoint2013默認使用claims based authentication,因此其賬號會是i:0#.w|/domain name這樣的格式,如何去掉前面的內容,只保留登陸賬號呢?dom

參見https://sharepoint.stackexchange.com/questions/113215/problem-with-i0-w-domain-name的內容,使用以下方法便可:ide

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;的引用。spa

相關文章
相關標籤/搜索