Click here to Skip to main content
15,867,330 members
Articles / All Topics

SSL Connection Error When Debugging via Localhost in Google Chrome

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
17 Jul 2015CPOL2 min read 49.2K   3   2
SSL Connection Error when debugging via Localhost in Google Chrome

The Problem

I recently created a new ASP.NET Web Application project in Visual Studio. Upon launching it for debug in the Google Chrome browser, I was greeted with an SSL Connection Error screen from Chrome. I also noticed that the URL was changed from “http:” to “https:” (https://localhost:49500/).

Image 1

I looked at my project settings in Visual Studio under the Web tab and found that my Project URL was set to http://localhost:49500/, which indicated to me that the project should have been launched in as http, not https.

Project Settings with Http

There was no launching as http, and the fact that my browser was demanding that the site be secured was causing me to not be able to load and debug my project.

The Cause

I didn’t want my project launched as https and couldn’t understand why this was happening. After consulting with an associate (thanks Tim!), I discovered that this problem was caused by a custom header setting in the Web.config file of an old project that I had debugged, coupled with the HTTP Strict Transport Security cache in my Chrome browser.

I had debugged another, existing ASP.NET project in the recent past that had this customHeader line in its Web.config file:

XML
<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Strict-Transport-Security" 
        value="max-age=16070400; includeSubDomains" />
      </customHeaders>
    </httpProtocol>
</system.webServer>

The “Strict-Transport-SecuritycustomHeader line causes the server (in this case http://localhost) to add a line in the response header that a HSTS-capable browser (e.g. Google Chrome) reads. The browser takes this as a sign that any further communication (within the given time) with this server should be done via HTTPS only. Per the Chromium.org HSTS page:

When the browser sees this, it will remember, for the given number of seconds, that the current domain should only be contacted over HTTPS. In the future, if the user types http:// or omits the scheme, HTTPS is the default.

Since the project that I debugged had this header in its Web.config, I had told all HSTS-compatible browsers that I had used in debugging to always require http://localhost to default to https. This was borne out by looking at the HSTS cache in chrome by going to this URL in the Google Chrome browser: chrome://net-internals/#hsts and querying for localhost:

hsts cache in Chrome

The query shows “localhost” as being in the list of domains in the HSTS set.

The Solution

After finding that I had cached the domain “localhost” as requiring HTTPS, the solution was as simple as deleting the domain from my cache. In the Google Chrome browser, I navigated to chrome://net-internals/#hsts, typed “localhost” into the Delete domain text field, and hit Delete. After doing so, I queried for “localhost” again and received a “Not found”.

Localhost not found

Then, I re-launched my project from Visual Studio into Chrome and found that my ability to launch as HTTP had returned.

http load

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
United States United States
I'm a learner/coder/leader who is curious about how technologies and people work together to solve interesting problems. I have a passion for software and doing what I can to improve the lives of the people who create and use it.

Comments and Discussions

 
GeneralMy vote of 5 Pin
CH Z26-Jun-22 20:33
CH Z26-Jun-22 20:33 
Answer.net core Pin
Marco (Member 13041612)28-Aug-18 22:25
Marco (Member 13041612)28-Aug-18 22:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.