本文可帮助你解决安装 Microsoft Visual Studio 2015 Update 3 后针对不受信任的证书发生的警告。
原始产品版本: Visual Studio 2015
原始 KB 数: 3180222
现象
你已使用 Visual Studio 2015、Update 1 或 Update 2 的发布版本通过超文本传输协议安全(HTTPS)开发 Web 应用程序。 但是,安装 Visual Studio 2015 Update 3 后,开始收到有关不受信任的证书的警告。
原因
在 Visual Studio 的初始安装过程中,如果证书尚不存在,Internet Information Services (IIS) Express 会将自签名证书安装到 Certificates (Local Computer)\Personal\Certificates
文件夹中。 首次调试使用安全套接字层(SSL)的 Web 应用程序时,系统会提示将此证书安装到 Certificates - Current User\Trusted Root Certification Authorities\Certificates
文件夹中。
在升级到 Visual Studio 2015 Update 3 期间,IIS Express 会将新的 SHA256 自签名证书安装到 Certificates (Local Computer)\Personal\Certificates
文件夹中。 但是,由于文件夹中已安装证书 Certificates - Current User\Trusted Root Certification Authorities\Certificates
,Visual Studio 无法提示将新的 SHA256 证书安装到 Certificates - Current User\Trusted Root Certification Authorities\Certificates
该文件夹中。
方法 1:使用 PowerShell 脚本
注意
这是首选方法。
在 Windows PowerShell 集成脚本环境中运行以下脚本(ISE):
ipmo PKI $name = [GUID]::NewGuid() $cerFile = "$env:TEMP\$name.cer" $certs = Get-ChildItem Cert:\LocalMachine\My -DnsName localhost -SSLServerAuthentication | ? {($_.FriendlyName -eq 'IIS Express Development Certificate') -and ($_.SignatureAlgorithm.FriendlyName -ieq 'sha256RSA') -and ($_.EnhancedKeyUsageList.Count -eq 1)} if ($certs.Count -eq 0) { Write-Error 'Cannot find any SHA256 certificate generated by IIS Express. Please make sure that the latest version of IIS Express is installed.' } else { foreach ($cert in $certs) { Export-Certificate -Cert $cert.PSPath -FilePath $cerFile -Type CERT | Out-Null Import-Certificate -FilePath $cerFile -CertStoreLocation Cert:\CurrentUser\Root | Out-Null Remove-Item $cerFile -Force } Write-Host 'Successfully installed the certificate to Trusted Root Certification Authorities of the current user.' }
收到以下警告时单击“ 是 ”:
脚本运行完成后,应在 PowerShell ISE 命令窗口中看到以下消息:
已成功将证书安装到当前用户的受信任根证书颁发机构。
方法 2:将计算机配置为信任 IIS Express 证书
单击“开始”,键入“运行”,然后按 Enter 打开Microsoft管理控制台。 在 “运行 ”对话框中,键入 mmc,然后单击“ 确定”。
添加管理单元来管理本地计算机的证书。 为此,请按照下列步骤进行操作:
在“文件” 菜单上,单击“添加/删除管理单元” 。
在 “添加或删除管理单元 ”对话框中,选择“ 证书”,然后单击“ 添加”。
在 “证书” 管理单元对话框中,选择“ 计算机帐户”,然后单击“ 下一步”。
在 “选择计算机 ”对话框中,选择“ 本地计算机”,然后单击“ 完成”。
在“添加或删除管理单元”对话框中,再次选择“证书”,这次在“证书”管理单元对话框中选择“我的用户帐户”。
从
Certificates (Local Computer)\Personal\Certificates
中导出 SHA256 IIS Express 证书,如下所示:打开 IIS Express 开发证书,验证是否已选择 SHA256 证书。 然后单击“ 复制到文件”。
在“证书导出向导”中,选择“ 否”,不导出私钥,然后单击“ 下一步”。
在向导的下一页上,选择 DER 编码的二进制 X.509(。CER),然后单击“ 下一步”。
在向导的下一页上,选择磁盘上的位置,并按照剩余步骤操作,直到成功导出证书。
将导出的证书导入到以下位置:
Certificates - Current User\Trusted Root Certification Authorities\Certificates
为此,请按照下列步骤进行操作:
导航到
Certificates - Current User\Trusted Root Certification Authorities\Certificates
文件夹,然后单击“操作”,指向“所有任务”,然后单击“导入”。在“证书导入向导”中,浏览到导出的证书(受信任的根证书颁发机构),然后选择“ 将所有证书放入以下存储区”。
单击“下一步”,验证是否选择了正确的证书,然后单击“完成”。
成功导入自签名 IIS 证书后,在开发过程中将不再收到有关不受信任的证书的警告。