Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 承载令牌无法使用WebAPI的“我的授权”属性角色,用户名为空 我可以通过邮递员登录并从中获取令牌密钥 我可以使用[Authorize]属性调用api 但是当我设置角色[Authorize(roles=“Admin”)]时,我得到了以下服务器内部错误:_C#_Asp.net Web Api_Token_Roles_Authorize - Fatal编程技术网

C# 承载令牌无法使用WebAPI的“我的授权”属性角色,用户名为空 我可以通过邮递员登录并从中获取令牌密钥 我可以使用[Authorize]属性调用api 但是当我设置角色[Authorize(roles=“Admin”)]时,我得到了以下服务器内部错误:

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

“消息”:“发生错误。”

“ExceptionMessage”:“值不能为空。参数名称:用户名”

“ExceptionType”:“System.ArgumentNullException”

“StackTrace”:“at System.Web.Util.SecUtility.CheckParameter(String¶m、Boolean checkForNull、Boolean checkIfEmpty、Boolean checkForCommas、Int32 maxSize、String paramName)

这是我的密码:

  • 属性类:

  • 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));