SSL Binding in Visual Studio 2019
I ran into an issue where I was setting up a new development laptop and after installing Visual Studio 2019 and cloning a repo that made use of SSL binding I received an error stating that Visual Studio could not start IIS Express.
How I had to go about fixing this issue was unique enough that I felt that I need to share to hopefully help the next person out.
To get the technical context correct, let me go over what versions of software were in play.
Windows 10 Pro, Version 1909
Visual Studio 2019 Pro, Build 16.6.4
IIS Express 10.0, Build 10.0.1741 for 64 bit OS
.Net Core 3.1 WebAPI
.Net Core 3.1 Web (Using React)
Configuration
In Visual Studio, the API project was configured with the necessary settings as shown below. Take note of the added ‘s’ to the http references as this is what introduces the issue. By default, the https is not there.
LaunchSettings.json
Project Properties
Error
Once you run the application after adding the https from the default http an error appears like below.
The browser will open to the correct url but does not load the page to an error stating that “ERR_CONNECTION_RESET”.
The Fix
The best solution that I have found was to go and remove all localhost certificates that were installed by IIS and update the applicationhost.config file that is produced by Visual Studio.
MMC
Start MMC by going to the Windows run command (win+r) and typing in mmc and press enter.
From here, add the snap in for Certificates.
You will need to do add the Certificates twice as you will need the Current User and Local Machine Certificates.
View the certificates in both the Personal and Trusted Root Certification Authorities folders and remove the localhost certificates.
Do this step for both Current User and Local Computer Certificate Snap Ins.
IIS Express
Go to Add or Remove Programs and uninstall IIS Express. You can download the install file from here.
Install IIS Express. As IIS Express installs it will automatically generate a new localhost cert and place it in your Personal Local Computer Cert store. Go and copy this newly created localhost certificate and paste it into the Trusted Root Certification Authorities Certificates folder.
Visual Studio
Go to this location and open the applicationhost.config file in a text file editor.
../../{projectName}/.vs/{projectName}/config
Search for the bindings section shown below.
Notice that the http and https binding are the same, update the http port to be in the 5XXXX range. Save.
Build and Run the application.
You should get the following pop ups, answer Yes to both.
Your Web page should now load with the https url without issue.
Conclusion
I feel that the root cause of this issue is a bug within Visual Studio 2019. When editing the ports and http/https URL paths Visual Studio is not properly handling creating the new bindings. This causes the localhost cert and bindings to it to become out of sync.
There may be other solutions to this issue but this was the solution I came up with to resolve the problem.
Happy Coding!
About Me
I am the Founder and CEO of PalmettoCloud, Senior Software Architect at ScanSource and a BBQ Jedi.
You can find more about me here on my personal site and on LinkedIn!
For your custom software needs, please check us out at PalmettoCloud!