3

我正在尝试在 Google Cloud Platform 中设置我的网络应用程序并使用 https。当浏览器尝试通过 https 端口连接时,Kestrel 会报告以下内容:

Hosting environment: Development
Content root path: /home/cvanem2/abc/HelloWorldAspNetCore
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
dbug: HttpsConnectionAdapter[1]
      Failed to authenticate HTTPS connection.
System.IO.IOException: The handshake failed due to an unexpected packet format.
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Security.SslState.ThrowIfExceptional()
   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
   at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsServerAsync>b__51_1(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)ext)

我在我的生产代码中遇到了这个问题,但它也可以使用提供的示例代码轻松生成。如果您有谷歌云平台项目设置,以下是有关如何重现问题的说明:

  1. 打开 GCP 终端窗口
  2. sudo apt-get -y 安装 dotnet-sdk-2.1
  3. dotnet new razor -o HelloWorldAspNetCore
  4. cd HelloWorldAspNetCore/
  5. dotnet 开发证书 https
  6. 点网运行
  7. 将 Web 预览设置为端口 5001 并尝试打开。错误将显示在终端窗口中

完全相同的代码在 Windows PC 上运行良好。我还将 Windows 代码编译到 Windows 上的 linux docker 容器中并执行了 docker。如果代码在 docker 中执行,则会出现此问题,因此它似乎与运行 .net 代码的操作系统有关。我尝试使用 Wireshark 分析来自 Docker 映像的 TLS 数据包,但数据在前几个数据包之后被加密,并且没有出现任何错误。任何帮助,将不胜感激。

4

1 回答 1

4

可以更改launchSettings.json,修改https前的http

"WebApplication2": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "api/values",
  "environmentVariables": {      
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  **"applicationUrl": "http://localhost:5000;https://localhost:5001"**
}
于 2018-08-03T07:10:59.177 回答