当 运行 给出 "This site can't be reached" 时,来自模板的新 ASP.NET 核心应用程序

New ASP.NET core app from template when run gives "This site can't be reached"

我是 ASP.Net 核心的新手,我正在尝试在我的机器 (Windows 8.1) 上启动一个新的 ASP.NET 核心应用程序。我正在学习 https://docs.microsoft.com/en-us/aspnet/core/getting-started/?view=aspnetcore-3.1&tabs=windows 上的教程(这是最基本的):

  1. 通过以下方式创建应用程序:dotnet new webapp -o aspnetcoreapp
  2. 通过以下方式信任证书:dotnet dev-certs https --trust
  3. 运行 应用程序通过:dotnet watch 运行

当我 运行 应用程序并导航到 Chrome 中的 https://localhost:5001/ 时,我收到以下错误:

This site can’t be reached
The webpage at https://localhost:5001/ might be temporarily down or it may have moved permanently to a new web address.
ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY

我觉得这像是一个证书问题,所以我遵循了“信任开发证书部分”下的 link,并尝试通过以下方式删除并重新添加旧证书:

dotnet dev-certs https --clean
dotnet dev-certs https --trust

但这并没有帮助。

当我 运行 dotnet watch 运行 时,我没有看到任何错误。这是输出:

watch : Started  
info: Microsoft.Hosting.Lifetime[0]  
      Now listening on: https://localhost:5001  
info: Microsoft.Hosting.Lifetime[0]  
      Now listening on: http://localhost:5000  
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: D:\learn_code\aspnetcoreapp2  

昨天下载了新版的.NET,又试了下,感觉不是版本问题。我正在使用 3.1.402.

我还能做些什么来获得这个 运行ning 吗?谢谢。

更新:

这篇 Microsoft 文章提供了有用的信息,但它还指出 Windows 8 和 8.1 默认启用并启用了 TLS 1.2: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls#configuring-security-via-the-windows-registry

我也尝试了推荐的注册表设置,但没有用,我认为这可能针对 .NET Framework 而不一定是 .NET Core(但我对此不是 100% 确定)。 ..

另外,HTTP2 也有一些进展。我找到了这篇文章,这似乎暗示它是与 HTTP2 结合的密码: https://www.tecklyfe.com/how-to-fix-ns_error_net_inadequate_security-and-err_spdy_inadequate_transport_security-in-iis-on-windows-server-2016/

我尝试了 Nartac IISCrypto GUI 工具(这比手动编辑注册表设置容易得多)https://www.nartac.com/Products/IISCrypto/Download,单击“最佳实践”按钮并重新启动,但没有用。

tecklyfe 文章中还有一个关于在 Firefox 中禁用 HTTP2 的建议,它确实有效。所以,我认为答案可能在使用正确密码的领域。

dotnet 运行 看起来它在 Microsoft.Hosting.Lifetime 中启动,所以也许我可以弄清楚如何配置它?

尝试将协议添加到 Kestrel 配置中

ConfigureKestrel((context, options) =>
            {
                // development options for kestrel
                if (context.HostingEnvironment.IsDevelopment())
                {
                    options.Listen(IPAddress.Any, 5000);  // http:localhost:5000
                    options.Listen(IPAddress.Any, 5001, listenOptions =>
                    {
                        listenOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1;   // force http1 during dev.

                        //install certificate with private key
                        listenOptions.UseHttps(@"S:\Certs\SSL\example.com.pfx", "1234567", httpsOptions =>
                        {
                            httpsOptions.SslProtocols = System.Security.Authentication.SslProtocols.Tls;
                        });
                    });
                }
            });

根据这篇 Microsoft 文章 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#:~:text=Kestrel%20is%20a%20cross%2Dplatform,ASP.NET%20Core%20project%20templates。在“HTTP/2 支持”部分,

Kestrel has limited support for HTTP/2 on Windows Server 2012 R2 and Windows 8.1. Support is limited because the list of supported TLS cipher suites available on these operating systems is limited. A certificate generated using an Elliptic Curve Digital Signature Algorithm (ECDSA) may be required to secure TLS connections.

为了 运行 ASP.Net Windows 8.1 上的核心应用程序,将 Http1 配置为默认连接协议,方法是将此配置添加到 appsettings.json 文件中:

"Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http1"
    }
  }