Ubuntu 上的 C# HTTPS 服务器

标签 c# .net ubuntu https mono

我正在尝试从我的 C# HTTP 服务器获得在 Ubuntu 上工作的 HTTPS 连接。我已经在我的 HTTPListener 中启用了 HTTPS,就像在 Windows 上一样,但是我无法建立连接。
从文档:

If you create an HttpListener using https, you must select a Server Certificate for that listener. Otherwise, an HttpWebRequest query of this HttpListener will fail with an unexpected close of the connection.


我正看到这种情况发生。文档建议:

You can configure Server Certificates and other listener options by using Network Shell (netsh.exe). See Network Shell (Netsh) for more details. The executable began shipping with Windows Server 2008 and Windows Vista.


由于我在 Ubuntu 上并且我的服务器正在运行 Ubuntu Server,因此我无权访问此工具。如何在 Ubuntu 中达到同样的效果?

最佳答案

这取决于所使用的后端 Web 服务器。在 Ubuntu 上,您可能会使用 Kestrel。对于 Kestrel,可以使用以下方式定义 SSL 证书:

"Kestrel": {
"Certificates": {
  "Default": {
    "Path": "<path>/fullchain.pem",
    "KeyPath": "<path>/privkey.pem"
  }
},
"Endpoints": {
  "Http": {
    "Url": "http://*:80"
  },
  "Https": {
    "Url": "https://*:443"
  }
}
在 appsettings.json
有关如何为 Kestrel 设置 SSL 的更多信息,请参阅:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0

关于Ubuntu 上的 C# HTTPS 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70319570/

相关文章:

c# - Consumer 中 Confluence.Kafka 中的事务

c# - 值是逗号而不是点的范围验证

c# - 第一次打开应用程序时应用程序变慢

.net - DataGridView 何时从自定义 EditingControl 获取其值?

c++ - gcc 库函数的手册页

c# - 如何从 Web 服务代码 (C#) 访问内在 ASP.NET 对象?

c# - 在 Visual C# Express 中使用多个解决方案的良好实践

linux - 谁在 Linux 中调用 calloc() 时清零页面?

c# - .NET 中调用的动态拦截

在 Passenger + Nginx 中部署时,Rails 中的 MySql 错误