【问题标题】:Unable to start Kestrel when 'dotnet run''dotnet run' 时无法启动 Kestrel
【发布时间】:2019-08-31 08:56:56
【问题描述】:

我最近删除了我计算机上记住的一个 Wi-Fi。突然所有项目都无法运行。

这是控制台输出

$ dotnet run
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/Users/user/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
crit: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to start Kestrel.
System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found.
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)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

Unhandled Exception: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found.
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)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at testing.Program.Main(String[] args) in 

我使用的是 Visual Studio 2019 for Mac。 .NET Core SDK 和运行时版本:

dotnet --version
2.2.401

dotnet --list-sdks
2.2.401 [/usr/local/share/dotnet/sdk]

dotnet --list-runtimes
Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

我查看了一些 stackoverflow 答案,他们认为这可能是证书问题。我曾尝试使用dotnet dev-certs 工具来解决,但它不起作用。另外我遇到了一些奇怪的事情:

dotnet dev-certs https --check --verbose
No valid certificate found.

dotnet dev-certs https
A valid HTTPS certificate is already present.

dotnet dev-certs https --trust
Trusting the HTTPS development certificate was requested. If the certificate is not already trusted we will run the following command:
'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain <<certificate>>'
This command might prompt you for your password to install the certificate on the system keychain.
A valid HTTPS certificate is already present.

dev-certs 检查选项与创建新搜索的命令产生矛盾的结果

dotnet-dev-certs 版本是2.2.0

在我的钥匙串中,没有 localhost 的证书。然后我尝试重新安装 dotNET SDK 和 Visual Studio,但也没有用。

【问题讨论】:

  • 如果我是你,我会忘记 kestrel 上的 SSL。这种轻量级容器更适合仅用于 HTTP 的连接,并且可以使用另一个 Web 服务器在您安装它的机器之外进一步公开应用程序。 IIS 或 Nginx 都可以。
  • 太棒了!我用过 Nginx 并且工作过!非常感谢!

标签: asp.net asp.net-core asp.net-web-api


【解决方案1】:

我遇到了同样的问题,最后,我从在命令提示符下做两件事中解脱了。

  1. dotnet dev-certs https --clean
  2. dotnet dev-certs https --trust

C:\Users\saifs>dotnet dev-certs https --clean 从机器上清除 HTTPS 开发证书。可能会显示提示以确认删除某些证书。

C:\Users\saifs>dotnet dev-certs https HTTPS 开发者证书生成成功。

C:\Users\saifs>dotnet dev-certs https --trust 已请求信任 HTTPS 开发证书。如果证书以前不受信任,将显示确认提示。在提示上单击是以信任证书。 已存在有效的 HTTPS 证书。

【讨论】:

    猜你喜欢
    • 2020-04-20
    • 2022-01-07
    • 2022-07-26
    • 2021-12-12
    • 2021-02-04
    • 2023-03-23
    • 2020-04-30
    • 1970-01-01
    • 2019-02-08
    相关资源
    最近更新 更多