开发时在ASP.NET Core 2.1中使用SSL证书 [英] Use SSL Certificate in ASP.NET Core 2.1 while Developing
问题描述
在ASP.NET Core 2.1 I应用程序的appSettings文件中,我具有以下内容:
On an ASP.NET Core 2.1 I application appSettings file I have the following:
"Kestrel": {
"Certificates": {
"Default": {
"Path": "localhost.pfx",
"Password": "1234"
}
}
}
我使用dotnet命令创建了证书:
I created the certificate using the dotnet command:
dotnet dev-certs https -ep "localhost.pfx" -p 1234
然后我将localhost.pfx文件沿着appSettings文件复制到了项目根目录.
And I copied the localhost.pfx file to the project root along the appSettings file.
当我在 http://localhost:5000 上运行项目时,它会重定向到
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.
我在做什么错了?
推荐答案
简短回答
包括-trust
选项.
dotnet dev-certs https -ep "localhost.pfx" -p 1234 --trust
这将创建一个可与以下appsettings.json一起使用的证书:
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
-trust
选项将立即与Chrome配合使用;但是,使用Firefox,我们仍然需要添加安全例外.
The --trust
option will work right away with Chrome; with Firefox, though, we will still need to add a security exception.
使用-trust
意味着我们不再需要将"Kestrel"
部分添加到appsettings.json文件中.
Using --trust
means that we no longer need to add the "Kestrel"
section to the appsettings.json file.
这篇关于开发时在ASP.NET Core 2.1中使用SSL证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!