ASP.NET IIS Express 上的核心 3.1 应用程序:"This site can't be reached"

ASP.NET Core 3.1 app on IIS Express: "This site can't be reached"

我正在开发一个 ASP.NET 核心应用程序,我已将其从 v2.2 升级到 v3.1。

当我在未启用 SSL 的情况下使用 IIS Express 启动应用程序时,我在 Google Chrome 中收到此错误:

This site can't be reached. localhost refused to connect.

启用 SSL 时,我收到此错误:

This localhost page can't be found. No web page was found for the web address: https://localhost:44367.

我有一个 IIS 网站配置到我的应用程序所在的目录。在项目设置中,我可以将 'Launch' 设置为 'IIS',但是当我这样做时,我也会得到同样的错误。

我的 Web 项目设置的屏幕截图:

当我在 IIS Express 上使用相同的设置创建一个新的空白 ASP.NET Core 3.1 Web 项目并 运行 它时,它 运行 没问题。

根据其他地方的建议,我尝试了以下方法:

我很茫然。

这是我的 launchSettings.json 文件:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://myapplication.debug",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:54236",
      "sslPort": 44367
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Web": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

与新项目的 launchSettings.json 文件进行比较时,我看不出有任何显着差异。还有什么会导致这种失败吗?

我应该注意到我确实更改了端口号 - 它最初位于端口号 50192,但是当我尝试 运行 网站到该地址时(http://localhost:50192) it gives me a different error:

从 aspnetcore 2.2 升级到 3.1 时,我的 Program.cs 似乎遗漏了一些东西。

直到现在我有这个:

return WebHost.CreateDefaultBuilder(args)
       .ConfigureServices(services => services.AddAutofac())
       .UseStartup<Startup>();

在查看一个新的 v3.1 项目时,它有这样的东西:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });