首先要说的是,我下面描述的所有内容都完全超出了我的舒适区。我对这个东西的工作原理一无所知,我只知道它确实有效。
通过 Visual Studio 2022 运行 IIS Express 时,我通常(每约 4 小时)必须重新运行以下脚本,然后将新生成的证书拖到
Trusted Root Certificate Authorities\Certificates
中,以便让我的浏览器识别本地主机。如果我不运行该脚本,我只会收到一条标准错误消息,表明我的浏览器无法识别我尝试浏览的地址。
# port and appId are any randomly chosen port or guid
$name = 'localhost'
$port = 12345
$appId = '626feeb6-1ee1-4670-8d38-80b8139fe8ce'
Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -eq 'CN=' + $name } | Remove-Item
$thumb=(New-SelfSignedCertificate -DnsName $name -CertStoreLocation cert:\LocalMachine\My).Thumbprint.ToLower()
Invoke-Expression "netsh http delete sslcert ipport=0.0.0.0:$port"
Invoke-Expression "netsh http add sslcert ipport=0.0.0.0:$port appid='{$appId}' certhash=$thumb"
有谁知道我为什么需要这样做?
一个明显的猜测是证书刚刚过期。
您可以在 powershell 中使用以下命令检查您的证书到期日期
Get-ChildItem Cert:\LocalMachine\My | ForEach-Object {
Write-Host "Certificate Subject: $($_.Subject)"
Write-Host "Thumbprint: $($_.Thumbprint)"
Write-Host "Expiration Date: $($_.NotAfter)"
Write-Host "------------------------"
}
如果它们没有过期,但仍然停止为您工作,那么恐怕我们需要更多信息。在
Trusted Root Certificate Authorities\Certificates
中,旧证书是否仍然存在,您只需将其替换为新证书,还是会在 4 小时内从那里删除?