简体   繁体   English

IIS Express 上的 ASP.NET Core 3.1 应用程序:“无法访问此站点”

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

I'm working on an ASP.NET Core application that I have upgraded from v2.2 to v3.1.我正在开发一个从 v2.2 升级到 v3.1 的 ASP.NET Core 应用程序。

When I start the application using IIS Express without SSL enabled, I get this error in Google Chrome:当我在未启用 SSL 的情况下使用 IIS Express 启动应用程序时,我在 Google Chrome 中收到此错误:

This site can't be reached.无法访问此站点。 localhost refused to connect.本地主机拒绝连接。

When I enable SSL, I get this error instead:当我启用 SSL 时,我收到此错误:

This localhost page can't be found.找不到此本地主机页面。 No web page was found for the web address: https://localhost:44367 .未找到该网址的网页: https://localhost:44367

I have have an IIS website configured to the directory where my application sits.我有一个 IIS 网站配置到我的应用程序所在的目录。 In the project settings, I can set the 'Launch' setting to 'IIS', but when I do this I also get the same error.在项目设置中,我可以将“启动”设置设置为“IIS”,但是当我这样做时,我也会遇到同样的错误。

Screenshot of my web project settings:我的网络项目设置的屏幕截图: 在此处输入图片说明 . .

When I create a new blank ASP.NET Core 3.1 web project and run it with the same settings on IIS Express, it runs fine.当我创建一个新的空白 ASP.NET Core 3.1 Web 项目并在 IIS Express 上使用相同的设置运行它时,它运行良好。

Based on suggestions elsewhere, I have tried the following:根据其他地方的建议,我尝试了以下方法:

  • Cleaning and rebuilding清洁和重建
  • Deleting the .vs folder in the web project删除web项目中的.vs文件夹
  • Changing the port number (currently it is localhost:54236).更改端口号(当前为 localhost:54236)。
  • Enabling/disabling SSL启用/禁用 SSL
  • Restarting my machine重新启动我的机器
  • Loading up a fresh copy of my solution from Git on a separate working directory and trying to run it.在单独的工作目录上从 Git 加载我的解决方案的新副本并尝试运行它。

I'm at a loss.我不知所措。

Here is my launchSettings.json file:这是我的 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"
    }
  }
}

When comparing with the launchSettings.json file of a fresh project I can't see any notable difference.与新项目的 launchSettings.json 文件进行比较时,我看不出任何显着差异。 Is there anything else that would cause this failure?还有什么会导致这种失败吗?

I should note that I did change the port number - it was initially at port number 50192, but when I attempt to run the website to that address ( http://localhost:50192 ) it gives me a different error:我应该注意,我确实更改了端口号 - 它最初位于端口号 50192,但是当我尝试将网站运行到该地址 ( http://localhost:50192 ) 时,它给了我一个不同的错误: 在此处输入图片说明

It appears I was missing something in my Program.cs when upgrading from aspnetcore 2.2 to 3.1.从 aspnetcore 2.2 升级到 3.1 时,我的 Program.cs 中似乎缺少某些内容。

Until now I had this:直到现在我有这个:

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

On looking at a fresh v3.1 project, it had something like this instead:在查看一个新的 v3.1 项目时,它有类似的东西:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM