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