C# 承载令牌无法使用WebAPI的“我的授权”属性角色,用户名为空 我可以通过邮递员登录并从中获取令牌密钥 我可以使用[Authorize]属性调用api 但是当我设置角色[Authorize(roles=“Admin”)]时,我得到了以下服务器内部错误:
“消息”:“发生错误。” “ExceptionMessage”:“值不能为空。参数名称:用户名” “ExceptionType”:“System.ArgumentNullException” “StackTrace”:“at System.Web.Util.SecUtility.CheckParameter(String¶m、Boolean checkForNull、Boolean checkIfEmpty、Boolean checkForCommas、Int32 maxSize、String paramName) 这是我的密码:C# 承载令牌无法使用WebAPI的“我的授权”属性角色,用户名为空 我可以通过邮递员登录并从中获取令牌密钥 我可以使用[Authorize]属性调用api 但是当我设置角色[Authorize(roles=“Admin”)]时,我得到了以下服务器内部错误:,c#,asp.net-web-api,token,roles,authorize,C#,Asp.net Web Api,Token,Roles,Authorize,“消息”:“发生错误。” “ExceptionMessage”:“值不能为空。参数名称:用户名” “ExceptionType”:“System.ArgumentNullException” “StackTrace”:“at System.Web.Util.SecUtility.CheckParameter(String¶m、Boolean checkForNull、Boolean checkIfEmpty、Boolean checkForCommas、Int32 maxSize、Str
- 属性类:
- OAuthAuthorizationServerProvider类:
我在上面找到了解决方案:这个
问题就在这方面
identity.AddClaim(new Claim("username", username));
我将“用户名”更改为ClaimTypes.Name
identity.AddClaim(new Claim(ClaimTypes.Name, username));
identity.AddClaim(new Claim("username", username));
identity.AddClaim(new Claim(ClaimTypes.Name, username));