c# - 在 SharePoint 中检索作为声明用户的友好名称

标签 c# sharepoint claims

我会先解释一下我想要做什么。我传入了一个声明标识符,例如 0e.t|saml provider|<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccaaa5bebfb8e2a0adbfb88ca8a3a1ada5a2e2a0a3afada0" rel="noreferrer noopener nofollow">[email protected]</a> 。我想将其修剪为 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="284e415a5b5c0644495b5c684c47454941460644474b4944" rel="noreferrer noopener nofollow">[email protected]</a>

我很清楚这可以通过简单的字符串格式化来完成,但是,这不是很灵活,因此如果传递了我不期望的内容,则字符串格式化可能会失败。它只是更容易出现问题。

我想动态地执行此操作。这是我尝试过的。

尝试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|<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04626d7677702a6865777044606b69656d6a2a686b676568" rel="noreferrer noopener nofollow">[email protected]</a>

saml provider|<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7016190203045e1c11030430141f1d11191e5e1c1f13111c" rel="noreferrer noopener nofollow">[email protected]</a>

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbddd2c9c8cf95d7dac8cffbdfd4d6dad2d595d7d4d8dad7" rel="noreferrer noopener nofollow">[email protected]</a>

同样,所有这些都失败了。

我尝试的另一种方法,使用 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)是否有更好的方法无需字符串解析即可获取友好的声明用户名?

最佳答案

叹息不知怎的i:声明字符串的开头被删除。

应该阅读i:0e.t|saml provider|<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="187e716a6b6c3674796b6c587c77757971763674777b7974" rel="noreferrer noopener nofollow">[email protected]</a> 。一旦添加回来,一切就开始正常运行。

关于c# - 在 SharePoint 中检索作为声明用户的友好名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16528663/

相关文章:

c# - 如何使用 Graphics.Draw 高效渲染图 block ?

sharepoint - SharePoint 中的性能数据分析

希望进入 SharePoint 的 ASP.NET 开发人员 - 2007 或 2010?

asp.net-core - 如何处理 IdentityUser 更新并发失败?

c# - 在 Windows Mobile 6.5 上使用 Web 服务时导致 WebException 的原因是什么?

c# - 使静态类中的字典成为线程安全的?

c# - “可为空的对象必须有一个值。”对于 LINQ c# 中的列表

security - SharePoint 和 SAML : Is there any guard against a replay attacks?

c# - 设置 ClaimTypes.Name 不会导致 identity.name

c# - 如何从 IdentityServer4 请求用户信息