.Net Core Web API Swagger 没有找到该网址的网页:http://localhost/swagger

Posted

技术标签:

【中文标题】.Net Core Web API Swagger 没有找到该网址的网页:http://localhost/swagger【英文标题】:.Net Core Web API Swagger No webpage was found for the web address: 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 端口?

【问题讨论】:

【参考方案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
    
  

【讨论】:

以上是关于.Net Core Web API Swagger 没有找到该网址的网页:http://localhost/swagger的主要内容,如果未能解决你的问题,请参考以下文章

asp.net core web api 生成 swagger 文档

asp.net core web api 生成 swagger 文档

ASP.NET Core Web API使用静态swagger.json文件

在.net core web api中添加自定义属性到OpenAPI规范文件和swagger

ASP.NET Core 3.1 Web API(版本控制)和 Swagger UI 在发布到 Azure 后由于 MvcJsonOptions 而失败

.net core 使用swagger生成API文档