开发时在ASP.NET Core 2.1中使用SSL证书

问题描述 投票:3回答:1

在ASP.NET Core 2.1 I应用程序appSettings文件中,我有以下内容:

"Kestrel": {
  "Certificates": {
    "Default": {
      "Path": "localhost.pfx",
      "Password": "1234"
    }
  }
}  

我使用dotnet命令创建了证书:

dotnet dev-certs https -ep "localhost.pfx" -p 1234

我将localhost.pfx文件沿appSettings文件复制到项目根目录。

当我在http://localhost:5000上运行该项目时,它被重定向到https://localhost:5001

但是,我收到浏览器错误,说连接不安全,并要求我添加例外。

我究竟做错了什么?

asp.net-core asp.net-core-2.1
1个回答
4
投票

Short Answer

包括--trust选项。

dotnet dev-certs https -ep "localhost.pfx" -p 1234 --trust

这将创建一个可以使用这些appsettings.json的证书:

"Kestrel": {
  "Certificates": {
    "Default": {
      "Path": "localhost.pfx",
      "Password": "12345"
    }
  }
}

Notes

如果需要重新创建证书,请先清理证书存储区。

dotnet dev-certs https --clean

--trust选项可以立即使用Chrome;但是,对于Firefox,我们仍然需要添加安全例外。

使用--trust意味着我们不再需要将"Kestrel"部分添加到appsettings.json文件中。

© www.soinside.com 2019 - 2024. All rights reserved.