如何强制Visual Studio为运行Kestrel的.NET核心Web应用程序重新创建SSL证书?

wswtfjt7  于 2023-01-31  发布在  .NET
关注(0)|答案(2)|浏览(188)

创建Web项目时,Visual Studio会自动生成SSL证书并提示您安装该证书。一切正常。
证书现在已经过期,我不知道如何让它重新生成一个证书并重新开始这个过程。我试过从证书存储中删除所有现有的localhost证书并删除secrets.json,但似乎没有任何东西强迫它重新开始生成过程。

fjaof16o

fjaof16o1#

我终于想通了。
对于遇到此问题的其他任何人,修复它的步骤是:

  • 必须在证书管理器中删除所有localhost证书。可以在个人根目录和受信任根目录中找到这些证书
  • 必须删除secrets.json文件。该文件位于\Users\[user]\AppData\Roaming\Microsoft\UserSecrets\
  • 在powershell中,重新运行dotnet dev-certs https --trust以创建和安装一个新的,并提示信任

在这之后它会再次工作。

ndasle7k

ndasle7k2#

Visual Studio 2022工具Nuget包管理器包管理器控制台
软件包管理器控制台显示在底部时,键入以下命令

PM > dotnet dev-certs https --clean
        //Cleaning HTTPS development certificates from the machine. A prompt might get displayed to confirm the removal of some of the certificates.
        //HTTPS development certificates successfully removed from the machine.

        PM > dotnet dev-certs https -t
        //Trusting the HTTPS development certificate was requested.A confirmation prompt will be displayed if the certificate was not previously trusted.Click yes on the prompt to trust the certificate.
        //Successfully created and trusted a new HTTPS certificate.

        PM > dotnet dev-certs https --check
        //A valid certificate was found: C40087E6CA2F2A811F3BF78E3C5FE6BA8FA2XXXX - CN = localhost - Valid from 2023 - 01 - 27 23:21:10Z to 2024 - 01 - 27 23:21:10Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
        //Run the command with both--check and --trust options to ensure that the certificate is not only valid but also trusted.

相关问题