Maui Blazor 中文社区 QQ群:645660665

使用 Kestrel 自托管https 并作为 Windows 服务启动 Blazor 提示: 无法配置 HTTPS 端点。未指定服务器证书,找不到默认的开发者证书解决方法

原文链接 https://stackoverflow.com/questions/53300480/unable-to-configure-https-endpoint-no-server-certificate-was-specified-and-the/71026252#71026252

使用 Kestrel 自托管并作为 Windows 服务启动 Blazor 提示

Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)

搜遍了互联网终于找到一个可行办法

我使用 Powershell 和此命令创建了一个自签名证书。[我从互联网上的某个地方复制了这个 PowerShell 片段。不记得来源了。] 首先,请确保您的计算机上有一个可写位置:C:\temp\。(您可以使用任何其他路径,只要您的网络应用程序可以读取即可)

 $cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My
  $pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
  Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd

然后,在我的 appsertings.Development.json 中,我添加了此条目。

  "Kestrel": {
    "EndPoints": {
      "Https": {
        "Url": "https://localhost:5000",
        "Certificate": {
          "Path": "C:\\temp\\cert.pfx",
          "Password": "MyPassword",
          "AllowInvalid": "true"
        }
      }
    }
  }
posted @ 2024-02-08 10:17  AlexChow  阅读(2095)  评论(0编辑  收藏  举报