Use SSL Certificate in ASP.NET Core 2.1 while Developing

霸气de小男生 提交于 2021-02-17 14:54:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!