IIS Express上的ASP.NET Core 3.1应用程序:“无法访问此站点" [英] ASP.NET Core 3.1 app on IIS Express: "This site can't be reached"

查看:276
本文介绍了IIS Express上的ASP.NET Core 3.1应用程序:“无法访问此站点"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理从v2.2升级到v3.1的ASP.NET Core应用程序.

I'm working on an ASP.NET Core application that I have upgraded from v2.2 to v3.1.

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

When I start the application using IIS Express without SSL enabled, I get this error in Google Chrome:

无法访问此网站.本地主机拒绝连接.

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

启用SSL时,出现此错误:

When I enable SSL, I get this error instead:

找不到该本地主机页面.未找到以下网址的网页: https://localhost:44367 .

我在应用程序所在的目录中配置了一个IIS网站.在项目设置中,我可以将启动"设置设置为"IIS",但是当我这样做时,也会遇到相同的错误.

I have have an IIS website configured to the directory where my application sits. In the project settings, I can set the 'Launch' setting to 'IIS', but when I do this I also get the same error.

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

Screenshot of my web project settings: .

当我创建一个新的空白ASP.NET Core 3.1 Web项目并在IIS Express上以相同设置运行它时,它运行良好.

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.

根据其他建议,我尝试了以下操作:

Based on suggestions elsewhere, I have tried the following:

  • 清洁和重建
  • 删除Web项目中的.vs文件夹
  • 更改端口号(当前为localhost:54236).
  • 启用/禁用SSL
  • 重启我的机器
  • 在单独的工作目录上从Git加载我的解决方案的新副本,然后尝试运行它.

我很茫然.

这是我的launchSettings.json文件:

Here is my launchSettings.json file:

{
  "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文件进行比较时,我看不出任何明显的区别.还有什么会导致此故障的吗?

When comparing with the launchSettings.json file of a fresh project I can't see any notable difference. Is there anything else that would cause this failure?

我应该注意,我确实更改了端口号-最初是端口号50192,但是当我尝试将网站运行到该地址时(

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 (

推荐答案

从aspnetcore 2.2升级到3.1时,似乎我的Program.cs中缺少某些内容.

It appears I was missing something in my Program.cs when upgrading from aspnetcore 2.2 to 3.1.

直到现在我有了这个:

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

在查看新的v3.1项目时,它具有如下所示的内容:

On looking at a fresh v3.1 project, it had something like this instead:

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

这篇关于IIS Express上的ASP.NET Core 3.1应用程序:“无法访问此站点"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆