警告:Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] 无法确定重定向的 https 端口

问题描述 投票:0回答:1

我试图在 ASP dotnet 中运行我的第一个 Web API。问题是当我运行程序时 并打开:http://localhost:5074 浏览器显示:

找不到此本地主机页面

我尝试提供证书,但也没有成功。

我注意到它缺少 https: 端口,我该如何解决这个问题?

请我需要你的经验😢

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5074
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\Seth\DotNetPractice\ContosoPizza
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.

我需要配置我的 launchSettings.json 吗?

launchSettings 有哪些不足?

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:32954",
      "sslPort": 443
    }
  },
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:5074",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7297;http://localhost:5074",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
asp.net asp.net-web-api https
1个回答
0
投票

当您选择如下所示的

http
时,这是预期的行为。

enter image description here

enter image description here

如果选择

https
选项,则它将与 https 一起使用。

enter image description here

enter image description here

现在您面临“找不到此本地主机页面”404 错误

请按照我的步骤检查问题。

  1. 尝试在浏览器中打开网址

    http://localhost:5074/swagger
    ,检查是否可以看到swagger页面。

  2. 检查

    Program.cs
    文件中的 swagger 设置。

    app.UseSwagger();
    app.UseSwaggerUI();
    

    如果更改 RoutePrefix ,起始页的 url 将更改。

  3. 检查环境变量,可以在这里设置断点。

    enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.