简体   繁体   English

Microsoft Owin安全-声明构造函数值不能为null

[英]Microsoft Owin Security - Claims Constructor Value cannot be null

I am a bit new to Owin security. 我对Owin安全性有些陌生。 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. 我试图实现一个自定义用户管理器和用户存储,以查看该表并使用OOTB [Authorize(Roles =“ Contributor”)]属性为我的MVC应用程序授权用户。

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. 我使用一段代码,使用标准的Account控制器和下面的客户用户商店以一种非常基本的方式来完成此任务。

My problem is that the GetRolesAsync either isn't firing anymore or its getting an exception before it gets there from the Claims constructor: 我的问题是GetRolesAsync要么不再触发,要么在从Claims构造函数到达那里之前获取异常:

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. 我的ApplicationUser类已更改为最近将ID设置为PersonId。 OOTB MVC and Owin use the Id value which was not being set properly. OOTB MVC和Owin使用的ID值未正确设置。 Ensuring that this was set fixed this behaviour. 确保已设置此行为。

Thanks 谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请求其他索赔Owin Security - Request additional claims Owin Security 我不能引用Microsoft.Owin.Security.AuthenticationManager,为什么? - I cannot reference Microsoft.Owin.Security.AuthenticationManager, why? 找不到引用的组件“ Microsoft.Owin”,“ Microsoft.Owin.Security”,“ Microsoft.Owin.Security.Facebook”吗? - The referenced component 'Microsoft.Owin', 'Microsoft.Owin.Security', 'Microsoft.Owin.Security.Facebook' could not be found? Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerProvider - clientId 和 clientSecret 在尝试从 Postman 生成令牌时出现 null - Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerProvider - clientId and clientSecret coming null while trying to generate token from Postman Owin.Security.Providers-OpenIDAuthenticationMiddlewareBase派生类声明了FieldNotFoundException - Owin.Security.Providers - OpenIDAuthenticationMiddlewareBase derived class claims a FieldNotFoundException 使用Owin Middleware添加声明 - Add claims with Owin Middleware C#担保索赔价值已过时 - C# Security Claims Value Outdated Microsoft.Owin.Security.Basic NuGet包在哪里? - Where is the Microsoft.Owin.Security.Basic NuGet package? MSAL 与 Microsoft.Owin.Security.OpenIdConnect 是什么关系? - What is the relationship of MSAL to Microsoft.Owin.Security.OpenIdConnect? Microsoft.Owin.Security.Facebook:无法访问Facebook令牌 - Microsoft.Owin.Security.Facebook : Unable to reach facebook tokenEndpoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM