Microsoft Owin Security - 声明构造函数值不能为空

Microsoft Owin Security - Claims Constructor Value cannot be null

我对 Owin 安全性有点陌生。我有一个遗留应用程序,其中包含一个用户 table 以及其中为每个用户定义的特定角色。

我正在尝试实现自定义用户管理器和用户存储以查看 table 并使用 OOTB [Authorize(Roles = "Contributor")] 属性为我的 MVC 应用程序授权用户。

我有一段代码以非常基本的方式使用标准帐户控制器和下面的客户用户存储来完成此操作。

我的问题是 GetRolesAsync 要么不再触发,要么在从 Claims 构造函数到达那里之前收到异常:

参数名称:

value
   at System.Security.Claims.Claim..ctor(String type, String value, String valueType, String issuer, String originalIssuer, ClaimsIdentity subject, String propertyKey, String propertyValue)
   at System.Security.Claims.Claim..ctor(String type, String value, String valueType)
   at Microsoft.AspNet.Identity.ClaimsIdentityFactory`1.<CreateAsync>d__0.MoveNext()

知道为什么我会突然看到这个异常,因为我对身份声明并不真正感兴趣。我正在运行的示例是否有一些更改将其从基于角色的安全性转移到基于声明的安全性?

终于想通了

我的 ApplicationUser class 最近更改为将 Id 设置为 PersonId。 OOTB MVC 和 Owin 使用未正确设置的 Id 值。确保设置已修复此行为。

谢谢