我會先解釋我想要做的事情。我有一個索賠標識符被傳入,例如,0e.t|saml provider|[email protected]
。我想修剪到[email protected]
。以SharePoint中的索賠用戶身份檢索友好名稱
我很清楚,這可以用簡單的字符串格式化來完成,但是這不是很靈活,所以如果某些東西被傳遞,我不期望,字符串格式化可能會失敗。它更容易出現問題。
我想動態地做到這一點。這是我嘗試過的。
試圖EnsureUser
與權利要求書的標識符的上方,然後調用SPUser.Name:
SPUser spUser = SPContext.Current.Web.EnsureUser(spUserName);
userName = spUser.Name;
我試圖在EnsureUser
以下字符串作爲參數時,所有結果在異常:The user with the specified logonName cannot be found in Active Directory.
0e.t|saml provider|[email protected]
saml provider|[email protected]
再次,所有這些失敗。
另一種方法我試過了,用SPClaimProviderManager
(從this blog拉):
SPClaimProviderManager mgr = SPClaimProviderManager.Local;
if (mgr != null && SPClaimProviderManager.IsEncodedClaim(userName))
{
spUserName = mgr.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).Value;
}
我想確保我嘗試解碼的實際要求,而不是別的東西,所以我打電話IsEncodedClaim
。然而,這總是返回false
。
我的問題:
1)我在做什麼錯在這裏的結果在這兩個嘗試失敗?爲了正常運作,我需要做些什麼不同?
2)有沒有更好的方法來獲得一個友好的索賠用戶名沒有字符串解析?