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 @   AlexChow  阅读(2202)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 易语言 —— 开山篇
历史上的今天:
2023-02-08 完整记录一次 Microsoft Teams 登录过程
点击右上角即可分享
微信分享提示