我正在测试官方 Asp.Net 核心示例https://github.com/aspnet/AspNetCore.Docs/tree/master/aspnetcore/fundamentals/servers/httpsys/samples/3.x/SampleApp我正在使用 Visual Studio 2019 V16.4.0(.Net 3.1)
我注释掉了这一行// options.UrlPrefixes.Add("http://localhost:5005");
,因此它将分别为 https 和 http 使用默认端口 5001 和 5000。
问题 1:在 Visual Studio 中运行与执行 .exe 文件时,应用程序输出不同。
Visual Studio 显示它正在侦听https://localhost:5001。
信息:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] 用户配置文件可用。使用“C:\Users\xxx\AppData\Local\ASP.NET\DataProtection-Keys”作为密钥存储库和 Windows DPAPI 来加密静态密钥。 信息:Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0] 开始 信息:Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0] 监听前缀:https://localhost:5001/ 信息:Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0] 监听前缀:http://localhost:5000/ 信息:Microsoft.Hosting.Lifetime[0] 现在收听:https://localhost:5001 信息:Microsoft.Hosting.Lifetime[0] 现在收听:http://localhost:5000 信息:Microsoft.Hosting.Lifetime[0] 申请开始。按 Ctrl+C 关闭。 信息:Microsoft.Hosting.Lifetime[0] 托管环境:开发 信息:Microsoft.Hosting.Lifetime[0] 内容根路径:C:\Users\xxx\Downloads\AspNetCore.Docs-master\AspNetCore.Docs-master\aspnetcore\fundamentals\servers\httpsys\samples\3.x\SampleApp
但是,运行exe文件时,它不听https://localhost:5001
PS C:\Users\xxx\Downloads\AspNetCore.Docs-master\AspNetCore.Docs-master\aspnetcore\fundamentals\servers\httpsys\samples\3.x\SampleApp\bin\Debug\netcoreapp3.1> .\HttpSysSample.可执行程序 信息:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] 用户配置文件可用。使用“C:\Users\xxx\AppData\Local\ASP.NET\DataProtection-Keys”作为密钥存储库和 Windows DPAPI 来加密静态密钥。 信息:Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0] 开始 信息:Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0] 监听前缀:http://localhost:5000/ 信息:Microsoft.Hosting.Lifetime[0] 现在收听:http://localhost:5000 信息:Microsoft.Hosting.Lifetime[0] 申请开始。按 Ctrl+C 关闭。 信息:Microsoft.Hosting.Lifetime[0] 托管环境:生产 信息:Microsoft.Hosting.Lifetime[0] 内容根路径:C:\Users\xxx\Downloads\AspNetCore.Docs-master\AspNetCore.Docs-master\aspnetcore\fundamentals\servers\httpsys\samples\3.x\SampleApp\bin\Debug\netcoreapp3.1
问题二:网页https://localhost:5001/报错?(在 Visual Studio 中运行时)
网页在 Chrome 中返回以下消息。
无法访问此站点
连接被重置。
在 Edge 中,它显示
无法安全连接到此页面
这可能是因为该站点使用过时或不安全的 TLS 安全设置。如果这种情况持续发生,请尝试联系网站所有者。
更新:
运行.\HttpSysSample.exe --urls https://*:5005
启用带有命令行执行的 https。但是,它会得到与上面相同的错误。