大网数据广告活动
Web服务器与PHP

Warnings about an untrusted certificate

· 52CE 我爱测

Describes a problem that triggers warnings about an untrusted certificate after you install Visual Studio 2015 Update 3. Provides a resolution.

This article helps you resolve the warnings that occur for an untrusted certificate after you install Microsoft Visual Studio 2015 Update 3.

Original product version:   Visual Studio 2015
Original KB number:   3180222

Symptoms

You have developed web applications through Hypertext Transfer Protocol Secure (HTTPS) by using the release version of Visual Studio 2015, Update 1 or Update 2. However, after you install Visual Studio 2015 Update 3, you start receiving warnings about an untrusted certificate.

Cause

During the initial installation of Visual Studio, Internet Information Services (IIS) Express installs a self-signed certificate into the Certificates (Local Computer)\Personal\Certificates folder if a certificate doesn't already exist. The first time that you debug a web application that uses Secure Sockets Layer (SSL), you are prompted to install this certificate into the Certificates - Current User\Trusted Root Certification Authorities\Certificates folder.

During the upgrade to Visual Studio 2015 Update 3, IIS Express installs a new SHA256 self-signed certificate into the Certificates (Local Computer)\Personal\Certificates folder. However, because there is already a certificate installed in the Certificates - Current User\Trusted Root Certification Authorities\Certificates folder, Visual Studio fails to prompt you to install the new SHA256 certificate into the Certificates - Current User\Trusted Root Certification Authorities\Certificates folder.

Method 1: Use a PowerShell script

Note: This is the preferred method.

  1. Run the following script in the Windows PowerShell Integrated Scripting Environment (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.'
    }
    
  2. Click Yes when you receive the following warning:

    :::image type="content" source="./media/warnings-untrusted-certificate/certification-authority-warning.png" alt-text="Screenshot of the Security Warning window, which tells you are about to install a certification authority claiming to represent." border="false":::

  3. After the script finishes running, you should see the following message in the PowerShell ISE command window:

    Successfully installed the certificate to Trusted Root Certification Authorities of the current user.

Method 2: Configure computers to trust the IIS Express certificate

  1. Open the Microsoft Management Console by clicking Start, typing Run, and then pressing Enter. In the Run dialog box, type mmc, and then click OK.

    :::image type="content" source="./media/warnings-untrusted-certificate/mmc.png" alt-text="Screenshot of the Run window entering mmc." border="false":::

  2. Add a snap-in to manage certificates for the local computer. To do this, follow these steps:

    1. On the File menu, click Add/Remove Snap-in.

      :::image type="content" source="./media/warnings-untrusted-certificate/add-or-remove-snap-ins.png" alt-text="Screenshot of the File menu. The menu entry titled Add or Remove Snap-in and its keyboard shortcut Ctrl+M are highlighted." border="false":::

    2. In the Add or Remove Snap-ins dialog box, select Certificates, and then click Add.

      :::image type="content" source="./media/warnings-untrusted-certificate/select-certificates.png" alt-text="Screenshot of the Add or Remove Snap-ins dialog with Certificates item selected." border="false":::

    3. In the Certificates snap-in dialog box, select Computer account, and then click Next.

      :::image type="content" source="./media/warnings-untrusted-certificate/certificates-snap-in.png" alt-text="Screenshot of the Certificates snap-in dialog with Computer account option checked." border="false":::

    4. In the Select Computer dialog box, select Local Computer, and then click Finish.

      :::image type="content" source="./media/warnings-untrusted-certificate/select-computer.png" alt-text="Screenshot of the Select Computer dialog with local computer option checked." border="false":::

    5. In the Add or Remove Snap-ins dialog box, select Certificates again, and this time select My user account in the Certificates snap-in dialog box.

      :::image type="content" source="./media/warnings-untrusted-certificate/select-my-user-account.png" alt-text="Screenshot of the Certificates snap-in dialog with my user account checked." border="false":::

  3. Export the SHA256 IIS Express certificate from Certificates (Local Computer)\Personal\Certificates, as follows:

    1. Open the IIS Express Development Certificate, verify that you have selected the SHA256 certificate. and then click Copy to File.

      :::image type="content" source="./media/warnings-untrusted-certificate/copy-to-file.png" alt-text="Screenshot of selecting the SHA256 certificate and Copy to File button." border="true":::

    2. In the Certificate Export Wizard, select No, do not export the private key, and then click Next.

      :::image type="content" source="./media/warnings-untrusted-certificate/certificate-export-wizard.png" alt-text="Screenshot of Certificate Export Wizard dialog to select the No, do not export the private key option." border="false":::

    3. On the next page of the wizard, select DER encoded binary X.509 (.CER), and then click Next.

      :::image type="content" source="./media/warnings-untrusted-certificate/der-encoded-binary-x-509.png" alt-text="Screenshot of the page to check DER encoded binary X.509 (.CER) option." border="false":::

    4. On the next page of the wizard, select a location on disk, and follow the remaining steps until you have successfully exported the certificate.

  4. Import the exported certificate to the following location:
    Certificates - Current User\Trusted Root Certification Authorities\Certificates

    To do this, follow these steps:

    1. Navigate to the Certificates - Current User\Trusted Root Certification Authorities\Certificates folder, and then click Action, point to All Tasks, and then click Import.

    2. In the Certificate Import Wizard, browse to the certificate that you exported (Trusted Root Certification Authorities), and then select Place all certificates in the following store.

      :::image type="content" source="./media/warnings-untrusted-certificate/place-all-certificates.png" alt-text="Screenshot of the page to check Place all certificates in the following store. The store is Trusted Root Certification Authorities." border="false":::

    3. Click Next, verify that you selected the correct certificate, and then click Finish.

After you have successfully imported the self-signed IIS certificate, you will no longer receive warnings about an untrusted certificate during development.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 04/15/2024
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。