【问题标题】:VS2013 .NET 4.5 ASP.NET ADFS Get UPN out of ClaimsVS2013 .NET 4.5 ASP.NET ADFS 从声明中获取 UPN
【发布时间】:2018-06-21 03:26:43
【问题描述】:

如何从使用 ADFS 进行身份验证的 ASP.NET 站点的声明中获取用户主体名称 (UPN)?我想找回显示名称和 UPN,但我能看到的只是显示名称。

这就是我获取当前显示名称的方式。

用户.身份.名称

但是通过用户和身份对象查看 UPN 的位置并不清楚。

【问题讨论】:

    标签: asp.net visual-studio-2013 .net-4.5 wif adfs


    【解决方案1】:

    这就是我让它工作的方式......

    首先我发现了这个帖子:https://syfuhs.net/2010/09/09/converting-claims-to-windows-tokens-and-user-impersonation/

    这很有帮助,但我不得不将它从 WIF 3.5 转换为 4.5。这就是我最终拥有的。

    导入语句:

    Imports System
    Imports System.Linq
    Imports System.Threading
    Imports System.Security.Principal
    Imports System.Security.Claims
    

    要使用的代码片段:

    Dim identity As ClaimsIdentity = DirectCast(Thread.CurrentPrincipal.Identity, ClaimsIdentity)
    Dim upn As String = identity.Claims.Where(Function(c) c.Type = ClaimTypes.Upn).First().Value
    
    If [String].IsNullOrEmpty(upn) Then
        Throw New Exception("No UPN claim found")
    End If
    

    希望这对其他人有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-04
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      • 2014-03-12
      • 2016-05-04
      相关资源
      最近更新 更多