Sometimes we need to run our local website in HTTPS. We need to use an SSL certificate to run a local website in HTTPS mode. To achieve it we need to generate local SSL certificates. Generating an SSL certificate can be a tricky business.
I will show you how to generate a basic SSL certificate and install it for your local website in IIS.
Open PowerShell in Admin mode. Use the below script to generate an SSL certificate.
New-SelfSignedCertificate -DnsName "my.local.domain" -CertStoreLocation cert:\LocalMachine\My -FriendlyName "My Local Cert Name"
DnsName: dev.localhose.com this should match your localhost website name
New-SelfSignedCertificate -DnsName "mysite", "mysite.local", "mysite.siteco.re" -CertStoreLocation cert:\LocalMachine\My -FriendlyName "My Local Cert Name"
New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "dev.localhost.com" -FriendlyName "MySSLCertificate" -NotAfter (Get-Date).AddYears(10)
After executing the above command, you will see the success message below.
After the above step, we need to add this certificate to Trusted Root. Type “manage computer certificates” in windows search and open the Manage Computer Certificates
Expand Personal > Certificates you will see the generated certificate. Right-click on the certificate and click copy.
Now open Trusted Root Certificate Authorities > Certificates from the left side pane. Paste the copied certificate into this folder. Now your generated certificate is added to Trusted Root.
In the final step open your IIS and expand the Sites and select your website. Right Click on the website and choose “Edit Bindings”. Click Add to add HTTPS binding.
On the new windows choose the type as HTTPS and the hostname as dev.localhost.com. The hostname should match the name on the certificate.
Select the SSL certificate we generated and click okay.
Restart your website in IIS. Now you can debug your website using HTTPS.