c# - 声明类型为 "emails",然后 ClaimTypes.Email 为 null

标签 c# .net asp.net-core azure-ad-b2c

var userEmail = User.FindFirstValue(ClaimTypes.Email); --> getting null
var email = User.Claims.FirstOrDefault(c => c.Type == "emails")?.Value; --> getting valid email

options.TokenValidationParameters.NameClaimType = "name";

我正在开发 .net core 5。我的问题是 c.type 获取电子邮件,这就是它返回 null 的原因。对此有什么想法吗?

最佳答案

可能您的声明是自定义定义的。 因此,ClaimTypes.Email 的标准值在 System.Security.Claims.ClaimTypes

中定义
        internal const string ClaimType2005Namespace = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims";
...
        public const string Email = ClaimType2005Namespace + "/emailaddress";

相反,您对电子邮件的声明被定义为“电子邮件”。

您的代码中有自定义定义吗?

关于c# - 声明类型为 "emails",然后 ClaimTypes.Email 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68763526/

相关文章:

c# - 如何更改日期时间?

html - 将 silverlight 应用程序转换为 html 的最佳策略是什么?

c# - 亚音速 ORM 体验

dependency-injection - 通过依赖注入(inject)实现后台任务的 DbContext

c# - 我看到奇怪的 ActionLink 行为,为什么浏览器中显示的 url 没有显示看似正确的 Controller ?

c# - "Property elements cannot be in the middle of an element' s 内容。”WPF 应用程序中的错误

c# - 将System.Type强制转换为特定的类

c# - 2nd Page_Load 上的 NullReferenceException

javascript - ASP.NET Core 3.0 MVC 连接中的 SignalR 保持事件状态不起作用?

c# - 使用 .NET 时如何限制文件碎片?