参考Kestrel 文档,是否可以使用 appsettings.json 文件配置 https:
"HttpsInlineCertStore": {
"Url": "https://+:5002",
"Certificate": {
"Subject": "<coma separated multi-line subject name>",
"Store": "Root",
"Location": "LocalMachine"
}
Run Code Online (Sandbox Code Playgroud)
该证书肯定存在,下一个代码返回会找到它:
using (var certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
{
certStore.Open(OpenFlags.ReadOnly);
var certificates = certStore.Certificates.Find(
X509FindType.FindBySubjectDistinguishedName, "<coma separated multi-line subject name>", true);
return certificates .Count > 0 ? certificates [0] : null;;
}
Run Code Online (Sandbox Code Playgroud)
同时,如果通过 X509FindType.FindBySubjectName 搜索证书,它什么也找不到,我相信这就是问题所在,即使微软说 FindBySubjectDistinguishedName 是更具体的搜索。