【问题标题】:How to install ssl certificate without IIS in windows server 2016?如何在 Windows Server 2016 中安装没有 IIS 的 ssl 证书?
【发布时间】: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


【解决方案1】:

第 1 步:在您的主机中启用 IIS 功能。然后转到管理工具>IIS 管理器。

第 2 步:选择要为其启用 ssl 的站点。

第 3 步:在右侧的操作面板中,您将拥有编辑站点并选择绑定

第 4 步:在站点绑定中,如果已定义,请单击关闭或

1.点击添加

2.选择https

  1. 在ssl证书中,选择证书

  2. 点击确定然后关闭

第五步:在连接面板的site下>再次点击site,显示选中的网站首页。

第 6 步:在选定的网站中,点击 SSL 设置

第 7 步:在 ssl 设置中,选择 require ssl 并在客户端证书下选择接受。

第 8 步:申请

【讨论】:

    【解决方案2】:

    如果我理解正确,那么您在开发环境中使用 SSL 会很困难。我建议你看这里Enforce HTTPS in ASP.NET CORE。在页面上的这一点上,Trust the ASP.NET Core Development Certificates..,您可能会找到解决问题的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-15
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 2017-10-12
      • 2014-01-27
      • 2018-04-19
      相关资源
      最近更新 更多