问题
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?
回答1:
Short Answer
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"
}
}
}
Notes
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.
来源:https://stackoverflow.com/questions/52318308/use-ssl-certificate-in-asp-net-core-2-1-while-developing