【问题标题】:.Net Core Web API Swagger No webpage was found for the web address: http://localhost/swagger.Net Core Web API Swagger 没有找到该网址的网页:http://localhost/swagger
【发布时间】:2021-07-08 06:52:05
【问题描述】:

我正在开发 .NET 核心 Web API,我想将该项目与 Swagger 集成。

我已按照本文中的所有步骤进行操作 https://dev.to/amoenus/how-to-integrate-swagger-ui-in-a-net-core-web-api-application-amoenus-dev-13o1

现在项目没有在 IIS 上运行,所以要导航到 swagger,我输入了 http://localhost:8080/swagger。

因为我有这个在StartUp

app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API");
            c.RoutePrefix = string.Empty;
        });

老实说,我认为端口是 8080,因为我不知道我的端口是什么。

如果我不在 IIS 上运行,谁能告诉我是否可以大摇大摆,以及如何准确地知道我的 localhost 端口?

【问题讨论】:

    标签: .net asp.net-web-api swagger webapi


    【解决方案1】:

    设置位于launchSettings.json 中,位于 Web api 根目录的 Properties 文件夹下。以下是我的设置示例。

    "profiles": {
        "test-web-api": {
          "commandName": "Project",
          "dotnetRunMessages": "true",
          "launchBrowser": true,
          "launchUrl": "swagger",
          "applicationUrl": "https://localhost:5001;http://localhost:5000",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "local"
          }
        },
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "launchUrl": "swagger",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "local"
          },
          "use64Bit": true
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 2021-08-26
      • 2018-05-31
      • 2020-03-09
      • 2020-05-05
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多