Microsoft Owin安全-声明构造方法的值不能为null [英] Microsoft Owin Security - Claims Constructor Value cannot be null
问题描述
我对Owin安全性有些陌生.我有一个带有用户表的旧应用程序,并且在其中为每个用户定义了特定角色.
I am a bit new to Owin security. I have a legacy application with a user table and a specific role defined in it for each user.
我试图实现一个自定义用户管理器和用户存储,以查看该表并使用OOTB [Authorize(Roles ="Contributor")]属性为我的MVC应用程序授权用户.
I am trying to implement a custom user manager and user store to look at that table and authorize users for my MVC application using the OOTB [Authorize(Roles = "Contributor")] attributes.
我使用一段代码,使用标准的Account控制器和下面的客户存储,以非常基本的方式完成了该工作.
I had a piece of code working that did this in a very basic way using the standard Account controller with the customer user store below.
我的问题是GetRolesAsync要么不再触发,要么在从Claims构造函数到达那里之前获取异常:
My problem is that the GetRolesAsync either isn't firing anymore or its getting an exception before it gets there from the Claims constructor:
参数名称:
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类最近更改为将ID设置为PersonId.OOTB MVC和Owin使用的ID值未正确设置.确保对此行为进行了设置.
My ApplicationUser class had changed to set the Id to be PersonId recently. OOTB MVC and Owin use the Id value which was not being set properly. Ensuring that this was set fixed this behaviour.
谢谢
这篇关于Microsoft Owin安全-声明构造方法的值不能为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!