On an ASP.NET Core 2.1 I application appSettings file I have the following:
"Kestrel": {
"Certificates": {
"Default": {
"Path": "localhost.pfx",
"Password": "1234"
}
}
}
I created the certificate using the dotnet command:
dotnet dev-certs https -ep "localhost.pfx" -p 1234
And I copied the localhost.pfx file to the project root along the appSettings file.
When I run the project on http://localhost:5000 it is redirected to https://localhost:5001.
However, I receive the browser error saying the connection is not safe and asking me to add an exception.
What am I doing wrong?
SSL provides authentication by using Public Key Infrastructure certificates. The server must provide a certificate that authenticates the server to the client.
In order to run ASP.NET Core Apps on the . NET Framework it needs to only reference . Core NuGet packages which contains only the . NET Standard 2.0 builds.
Per OWASP, HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that's specified by a web app through the use of a response header. When a browser that supports HSTS receives this header: The browser stores configuration for the domain that prevents sending any communication over HTTP.
NET Core 2.1 and . NET Core 3.1 are long-term support versions, which means they're supported for 3 years after release. This is explained in the . NET Core Support Policy.
Include the --trust
option.
dotnet dev-certs https -ep "localhost.pfx" -p 1234 --trust
That creates a certificate that will work with these appsettings.json:
"Kestrel": {
"Certificates": {
"Default": {
"Path": "localhost.pfx",
"Password": "12345"
}
}
}
If you need to recreate the certificate, clean the certificate store first.
dotnet dev-certs https --clean
The --trust
option will work right away with Chrome; with Firefox, though, we will still need to add a security exception.
Using --trust
means that we no longer need to add the "Kestrel"
section to the appsettings.json file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With