I'm trying to play around with ASP.NET Core and SSL certificates, and I ran into something I don't understand before I'd hardly started.
I'm running VS Code and net5.0 in Linux Mint 20.1 (It's mostly Ubuntu).
I started with the Web API template:
dotnet new webapi
It installed and ran without issue, loading https://localhost:5001/ in the browser, which gave a 404, but both https://localhost:5001/swagger/index.html and https://localhost:5001/WeatherForecast loaded and ran without issue.
I then edited launch.json to add a uriFormat to the serverReadyAction, so it would load /WeatherForecast on every run:
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
"uriFormat": "%s/WeatherForecast"
},
Of course, I had installed the dotnet dev-cert, in earlier experiments. So I cleared the dev-cert and ran things again:
dotnet dev-certs https --clean
Then when I tried to run, I got the expected error:
Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
No cert, then no https.
Next step was to edit Properties/launchSettings.json, and to remove the https url:
"applicationUrl": "http://localhost:5000",
That resulted by a complaint by the HttpsRedirectionMiddleware:
Failed to determine the https port for redirect.
But it loaded the http page without issue.
So let's try some alternatives:
"applicationUrl": "http://127.0.0.1:5000"
Works fine.
Mint derives from Ubuntu and Ubuntu derives from Debian, and Debian puts the hostname (Linux-2020, in my case) in /etc/host, assigned to 127.0.1.1 (which is also an IP4 loopback address)
127.0.0.1 localhost
127.0.1.1 Linux-2020
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
So let's try some more:
"applicationUrl": "http://Linux-2020:5000"
With this, VS Code pops up a dialog - "Do you want Code to open the external website?" When I click "Open", it brings up a page with a bad URL:
http://[::]:5000/WeatherForecast
Just to see, I tried it with the IP:
"applicationUrl": "http://127.0.1.1:5000"
That also popped up the dialog, but when I clicked "Open" it brought up the page without issue:
http://127.0.1.1:5000/WeatherForecast
I've tried this with other domain names I've specified in /etc/hosts, and it doesn't matter what name I use, and it doesn't matter which IP4 loopback address I use - ASP.NET Core always tries to open http:/[::].
I've added a name with my machine's actual IP address (192.168.1.122) to /etc/hosts:
129.168.1.122 mine
When I use my actual IP:
applicationUrl": "http://192.168.1.122:5000"
it works. When I use the name:
applicationUrl": "http://mine:5000"
it doesn't.
What is going on?