模板中的新 ASP.NET Core 应用程序在运行时给出“无法访问此站点”

brr*_*rth 2 http2 asp.net-core

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

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

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

\n
\n

无法访问此站点\xe2\x80\x99
\n位于 https://localhost:5001/ 的网页可能暂时无法访问,或者可能已永久移至新网址。
\nERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY

\n
\n

对我来说,这感觉像是一个证书问题,所以我点击了“信任开发证书部分”下的链接,然后尝试通过以下方式删除并重新添加旧证书:

\n
dotnet dev-certs https --clean\ndotnet dev-certs https --trust\n
Run Code Online (Sandbox Code Playgroud)\n

但这没有帮助。

\n

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

\n
watch : Started  \ninfo: Microsoft.Hosting.Lifetime[0]  \n      Now listening on: https://localhost:5001  \ninfo: Microsoft.Hosting.Lifetime[0]  \n      Now listening on: http://localhost:5000  \ninfo: Microsoft.Hosting.Lifetime[0]  \n      Application started. Press Ctrl+C to shut down.  \ninfo: Microsoft.Hosting.Lifetime[0]  \n      Hosting environment: Development  \ninfo: Microsoft.Hosting.Lifetime[0]  \n      Content root path: D:\\learn_code\\aspnetcoreapp2  \n
Run Code Online (Sandbox Code Playgroud)\n

我昨天下载了新版本的.NET并再次尝试,所以我不认为这是版本问题。我正在使用 3.1.402。

\n

我还能做些什么来让它运行吗?谢谢。

\n

更新:

\n

这篇 Microsoft 文章提供了有用的信息,但它还指出 Windows 8 和 8.1 默认情况下已启用 TLS 1.2:\n https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls #通过 Windows 注册表配置安全性

\n

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

\n

此外,HTTP2 也有更多的功能。我发现这篇文章,这似乎暗示它是与 HTTP2 结合的密码:\n https://www.tecklyfe.com/how-to-fix-ns_error_net_inadequate_security-and-err_spdy_inadequate_transport_security-in-iis-on- windows-server-2016/

\n

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

\n

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

\n

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

\n

brr*_*rth 5

根据这篇微软文章 https://learn.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 在 Windows Server 2012 R2 和 Windows 8.1 上对 HTTP/2 的支持有限。支持有限,因为这些操作系统上可用的受支持 TLS 密码套件列表有限。可能需要使用椭圆曲线数字签名算法 (ECDSA) 生成的证书来保护 TLS 连接。

为了在 Windows 8.1 上运行 ASP.Net Core 应用程序,请将此配置添加到 appsettings.json 文件中,将 Http1 配置为默认连接协议:

"Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http1"
    }
  }
Run Code Online (Sandbox Code Playgroud)