安裝 Visual Studio 2015 Update 3 之後有關不受信任憑證的警告
本文可協助您解決安裝 Microsoft Visual Studio 2015 Update 3 之後,未受信任憑證所發生的警告。
原始產品版本: Visual Studio 2015
原始 KB 編號: 3180222
徵狀
您已使用 Visual Studio 2015、Update 1 或 Update 2 的發行版,透過 Hypertext Transfer Protocol Secure (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 Management Console。 在 [ 執行] 對話框中,輸入 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 憑證之後,您將不會再在開發期間收到有關不受信任憑證的警告。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應