简体   繁体   中英

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

We are running a web API with ASP.NET Core on IIS Express locally. We are using a custom domain name configured in the hosts-file.

This works fine, but we have to manually trust the site in Chrome every now and then, so we would like to set IIS Express up to use our SSL-certificate.

IIS Express is configured in launchSettings.json:

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

How can we configure IIS Express to use our SSL Certificate?

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

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

First make a new certificate with the hostname replaced, ensure its made on the local machine.

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")

Now we need to copy it into the trusted certificates for the local machine: open "mmc" Add snapin for the certificate manager for the local machine (not personal user) find the certificate and copy it over to "Trusted Root Certificate Authorities" 毫米波

Open up the certificate and copy the 'thumbprint' detail. 在此处输入图片说明

Next you need to tell IIS to use this certificate. Open an admin cmd prompt and navigate to the IIS express folder at C:\\Program Files (x86)\\IIS Express then run:

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

Thanks to: 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://stackoverflow.com/a/38953547/1079267
https://devblogs.microsoft.com/aspnet/configuring-https-in-asp-net-core-across-different-platforms/

Jexus Manager provides you the user interface to add server certificates and change site bindings.

http://jexusmanager.com

You should import this certificate to Trusted Root Certification Authorities on each machine you run this App. Easiest way to do this is open this certificate directly from browser. Not sure about Chrome and Firefox, but it works for IE for sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM