Install Self-Signed certificate for localhost website

Install Self-Signed certificate for localhost website

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.

No alt text provided for this image

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>
No alt text provided for this image

<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"
No alt text provided for this image

<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.

No alt text provided for this image
Select Local Machine and click Next
No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

You can see that now we have two site bindings: http and https.

No alt text provided for this image

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



Pallavi Chhabra

Project Manager at Infosys

5 年

Good work Raman :)

Patrick Wilkins

Principal Agile team lead at Raytheon

5 年

Good job Raman.

回复
Gaurav Purwaha

PMP | Senior BI and Analytics Professional | Data Enthusiast |Strategist|Automation Lead | Data Visualisation Expert | Digital Transformation

5 年

Good going Raman !!

回复

要查看或添加评论,请登录

Raman Gupta的更多文章

  • Sitecore 9.3 Local Installation

    Sitecore 9.3 Local Installation

    Sitecore 9.3 was announced at the Sitecore Symposium 2019 and the initial update has been released last week.

    2 条评论

社区洞察

其他会员也浏览了