Install Self-Signed certificate for localhost website
Raman Gupta
Sitecore Technology MVP| Sitecore XM Cloud Certified | Contentstack Implementation Certified | DXP Solution Architect
Problem Statement: While I was working with the Sitecore website having E-Commerce functionality, we need to test various web-services calls like payment gateways, login, my account, and other applications securely in our localhost. Anything and everything, including Google Chrome, now asks you to have a secure URL that starts with https://, which is a pain for most of the developers, as there’s a cost involved in it. For those who don’t know, we can create a self-signed certificate and make it trusted locally, to test out things.
In this article, I’m going to show you how to set up a local development environment that uses HTTPS with ASP.NET on Windows. I’ll show you how to create self-signed certificates and add them to your trusted root certificate store in order to get rid of the annoying browser messages.
1. Create a Self-Signed SSL Certificate
First of all, we need to create an SSL certificate to bind it with our local website <LocahostURL>.
To do this, open window PowerShell with the administrator in the local machine and run the below command
New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname <LocahostURL>
<LocahostURL> is localhost URL of your website
This will create a self-signed SSL server certificate in the computer MY store with the subject alternative name, Subject and Issuer name set to the localhost website URL.
Note: Please copy/note down the Thumbprint value generated.
2. Export certificate from the certificate store into a file
Now we need to export this certificate from a certificate store to a file. The private key is not included in the export.
Export-Certificate -Cert cert:\localMachine\my\<Thumbprint-of-cert> -FilePath "C:\certificates\<LocahostURL>.cer"
<Thumbprint-of-cert> is the Thumbprint value generated in step 1.
<LocahostURL> is the local host domain URL.
This will export a certificate to the file system as a Microsoft serialized certificate store without its private key.
3. Add the self-signed certificate as a trusted certificate authority
Go to C:\certificates and look for <LocahostURL>.cer. double click on this.
Click Install Certificate on the window opened and follow the below screenshots for further steps.
4. Add https Binding
Now, we need to bind the https protocol to our website. Go to IIS manager and select the website, which we created earlier. Click on the bindings link in the right-side pane. This will open the Site Bindings dialog box, as shown below.
Now, we need to add the https binding, so click on the Add button. From the Add Site Binding popup, select Type as https and select our certificate <LocahostURL> from the SSL certificate dropdown. Click OK.
You can see that now we have two site bindings: http and https.
Now open the browser and enter https://<LocahostURL> to see the page.
Reference: https://docs.microsoft.com/en-us/powershell/module/pkiclient/new-selfsignedcertificate?view=win10-ps
Hope the article was interesting and informative. Let's discuss more in the comments below and once again, until the next blog post! :)
You can also read my blog post to install new Sitecore 9.3 instance in the local machine here
Project Manager at Infosys
5 年Good work Raman :)
Principal Agile team lead at Raytheon
5 年Good job Raman.
PMP | Senior BI and Analytics Professional | Data Enthusiast |Strategist|Automation Lead | Data Visualisation Expert | Digital Transformation
5 年Good going Raman !!