【发布时间】:2019-10-06 10:49:50
【问题描述】:
我有一个基于asp.net core MVC的项目;我想使用 SSL 证书来使用 https,但是在运行我的项目时,它没有显示 https 地址。我无法在我的 Windows 服务器中使用 IIS。但在 Windows 10 中一切正常。
我正在尝试在 Windows 服务器中安装 SSL 证书,以便在我的项目中使用 https。
public static IWebHost BuildWebHost(string[] args)
{
var host = "0.0.0.0";
var http_port = 40000;
var https_port = 40001;
if (args.Length > 0) host = args[0].Trim();
if (args.Length > 1) http_port = Convert.ToInt32(args[1].Trim());
if (args.Length > 2) https_port = Convert.ToInt32(args[2].Trim());
return
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
//
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
options.Limits.MaxRequestBufferSize = null;
options.Limits.MaxRequestHeaderCount = 1000;
options.Limits.MaxRequestHeadersTotalSize = 256 * 1024;
options.Listen(IPAddress.Parse(host), http_port);
using (var store = new X509Store(StoreName.My))
{
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", false);
if (certs.Count > 0)
{
var certificate = certs[0];
options.Listen(IPAddress.Parse(host), https_port, listenOptions =>
{
listenOptions.UseHttps(certificate);
});
}
}
}).Build();
}
我希望输出看到 https://0.0.0.0:40001,但在 Windows 服务器中我只有 http://0.0.0.0:40000。
Windows 服务器的图像 Windows server
Windows 10 的图像: Windows 10
【问题讨论】:
-
@AlliterativeAlice,在我使用了
dotnet dev-certs https --trust之后,我得到了这个错误暴击:Microsoft.AspNetCore.Server.Kestrel[0] 无法启动 Kestrel。 -
对不起,我尝试运行您的代码,它对我有用。也许尝试将
new X509Store(StoreName.My)更改为new X509Store()以使用默认存储?
标签: ssl asp.net-core ssl-certificate windows-server-2016