升级后,
在Swagger UI中,我可以创建一个不记名令牌,但是当我试图使用它时,我得到一个401。
在错误日志中,我看到
AuthenticationScheme:“Bearer”未通过身份验证
和
不支持“发布”请求
和
请求已成功匹配名为“null”且模板为的路由
2020-09-01 04:58:25.004 +10:00 [Information] [Microsoft.AspNetCore.Hosting.Diagnostics] [{ Id: 1 }] Request starting HTTP/2.0 POST https://localhost:44348/api/job-management/get-user-counts application/json 18
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler] [{ Id: 9, Name: "AuthenticationSchemeNotAuthenticated" }] AuthenticationScheme: "Bearer" was not authenticated.
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware] [{ Id: 1, Name: "MethodNotSupported" }] "POST" requests are not supported
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.Rewrite.RewriteMiddleware] [{ Id: 1, Name: "RequestContinueResults" }] Request is continuing in applying rules. Current url is "https://localhost:44348/api/job-management/get-user-counts"
2020-09-01 04:58:25.006 +10:00 [Debug] [Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware] [{ Id: 1, Name: "MethodNotSupported" }] "POST" requests are not supported
2020-09-01 04:58:25.006 +10:00 [Debug] [Microsoft.AspNetCore.Routing.Tree.TreeRouter] [{ Id: 1, Name: "RequestMatchedRoute" }] Request successfully matched the route with name 'null' and template '"api/job-management/get-user-counts"'
我想过使用VS2019生成一个新的示例api,但是我找不到适用于JWT的示例api。
在配置服务中,我添加了
services.AddMvc(option => option.EnableEndpointRouting = false);
我应该如何解决问题?
[更新]
我已经浏览了Microsoft升级指南,但没有发现我错过了任何东西。
我在这个问题上找到了答案
我已经正确地转换为使用OpenApiParameter,但我错过了步骤
Schema = new OpenApiSchema() { Type = "String" }
我想我的问题不是重复的,因为我得到的错误可能会帮助其他人找到答案。