ASP.NET Core + IIS Express 如何设置 SSL 证书

ASP.NET Core + IIS Express how to setup SSL Certificate

我们是 运行 一个在本地 IIS Express 上具有 ASP.NET 核心的 Web API。我们正在使用主机文件中配置的自定义域名。

这工作正常,但我们必须时不时地手动信任 Chrome 中的站点,因此我们希望将 IIS Express 设置为使用我们的 SSL 证书。

IIS Express 配置在 launchSettings.json:

"iisExpress": {
  "applicationUrl": "http://applocal.ourdomain.com:5000",
  "sslPort": 44300
}

我们如何配置 IIS Express 以使用我们的 SSL 证书?

您应该将此证书导入您 运行 此应用程序的每台计算机上的受信任的根证书颁发机构。最简单的方法是直接从浏览器打开此证书。不确定 Chrome 和 Firefox,但它肯定适用于 IE。

Jexus Manager 为您提供添加服务器证书和更改站点绑定的用户界面。

http://jexusmanager.com

在机器上安装证书,然后在cmd中运行:

"C:\Program Files (x86)\IIS Express\IisExpressAdminCmd.exe" setupSslUrl -url:https://my.domain.name:<port> -CertHash:<Certificate thumbprint>

首先制作一个替换主机名的新证书,确保它是在本地机器上制作的。

Powershell: New-SelfSignedCertificate -NotBefore (Get-Date) -NotAfter (Get-Date).AddYears(1) -Subject "YOUR.DOMAIN.NAME" -KeyAlgorithm "RSA" -KeyLength 2048 -HashAlgorithm "SHA256" -CertStoreLocation "Cert:\LocalMachine\My" -KeyUsage KeyEncipherment -FriendlyName "HTTPS PROJECTNAME development certificate" -TextExtension @("2.5.29.19={critical}{text}","2.5.29.37={critical}{text}1.3.6.1.5.5.7.3.1","2.5.29.17={critical}{text}DNS=YOUR.DOMAIN.NAME")

现在我们需要将其复制到本地计算机的受信任证书中: 打开“mmc” 为本地机器(非个人用户)的证书管理器添加管理单元 找到证书并将其复制到“受信任的根证书颁发机构”

打开证书并复制 'thumbprint' 详细信息。

接下来你需要告诉IIS使用这个证书。 打开管理员 cmd 提示符并导航到位于 C:\Program Files (x86)\IIS Express 的 IIS Express 文件夹,然后是 运行:

IisExpressAdminCmd.exe setupSslUrl -url:https://YOUR.DOMAIN.NAME:PORTNUMBER -CertHash:THUMBPRINT

感谢: https://improveandrepeat.com/2020/05/how-to-change-the-https-certificate-in-iis-express/
https://www.sonicwall.com/support/knowledge-base/how-can-i-import-certificates-into-the-ms-windows-local-machine-certificate-store/170504615105398/

https://devblogs.microsoft.com/aspnet/configuring-https-in-asp-net-core-across-different-platforms/