Many a times, you need to run our local website in the HTTPS. You need to use an SSL certificate to run a local website in the HTTPS mode. To achieve this, you need to generate the local SSL certificates but that can be a very tricky business.
In this blog you will learn how to generate a basic SLL certificate and install it for your local website in the IIS.
Open the PowerShell in Amind mode and use the below give script to generate the 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 you have executed the above command, you will be able to see the success message as shown below.
Once the above steps are completed, you need to add this certificate to the Trusted Root. Type “manage computer certificates” in windows search and then open the Manage Computer Certificates.
Expand Personal > Certificates
Here you will see the generated certificate. You can right click on it and copy.
Now, open the Trusted Root Certificate Authorities > Certificates from the left side pane and paste the copied certificate in this folder. Your generated certificate is now added to the Trusted Root.
In the last final step, open your IIS and expand the Sites. Select your website, right click on it and choose “Edit bindings.” Click Add to add the 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.
Now, select the SSL certificate you generated and click okay.
Restart your website in IIS. Now you can debug your website using HTTPS.