首页 > 解决方案 > 除登录外的所有 API 上的 Swagger 401

问题描述

我可以登录 Swagger(出于某种原因,我必须先为访问令牌输入虚假文本)并成功取回访问令牌。但是,当我使用此访问令牌发布到任何其他 Api 时,我总是返回错误 401

在此处输入图像描述

这曾经有效,所以我不知道是我们升级到 .Net 5 的原因还是其他原因。

这是我们为 launchSettings.json 提供的内容:

  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:5000",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
      }
    },
    "MyApp": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
      }
    }
  }
}

我们正在使用 6.1 版的 Swashbuckle

标签: swagger

解决方案


推荐阅读