简体   繁体   中英

Microsoft Owin Security - Claims Constructor Value cannot be null

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.

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.

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.

My problem is that the GetRolesAsync either isn't firing anymore or its getting an exception before it gets there from the Claims constructor:

Parameter name:

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()

Any ideas why I would suddenly be seeing this exception since I am not really interested in Claims for the identity. Has there been some change in my examples thats working that has moved this from Roles based to Claims based security?

I finally figured it out.

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.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM