【发布时间】:2021-05-24 07:30:05
【问题描述】:
我的 ASP.NET 服务器在星期五运行良好。今天(星期一)我什至无法启动它。错误是:
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 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)
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)
我尝试了很多次dotnet dev-certs https --trust 无济于事。每次它都会提示我信任证书,每次都使用不同的指纹。
...但没有任何变化,服务器仍然失败并显示相同的错误消息。 dotnet dev-certs https --check 只是说No valid certificate found. 我试过dotnet dev-certs https --clean 声称成功(但不显示任何提示),然后dotnet dev-certs https --trust 但在我启动服务器时仍然出现同样的错误。
我尝试在控制面板 (certmgr.msc) 中查看证书管理器,因为这样做似乎可以帮助其他人(在不同站点上)解决相同的错误,但我不得不承认我对看过。以下是“个人”下显示的内容:
我已经发现服务器通过 IIS 运行良好,使用 Visual Studio 2019 中的 IIS 配置文件运行。好的,我可以调整客户端代码以与不同的 TCP 端口通信,或者学习如何更改 IIS 服务器端口(launchSettings.json 对吗?).. 但我宁愿了解这里实际发生了什么问题,并学习如何正确修复它。
如果有帮助,我的 Startup.Configure() 会说:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// for options and correct order, see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-3.1
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
// app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
}
所以:
- 如何以实际可行的方式将开发证书放入默认证书位置(无论在哪里??)?
- 或者,我如何自己创建开发证书,以及如何告诉我的服务器在哪里可以找到它?
- 或者,我如何制作一个真正的证书(来自我组织的“官方”证书??),然后我如何使用它来让客户端和服务器实际检查它,以获得良好的安全性?
【问题讨论】:
-
证书需要安装在机器和用户证书存储区(在注册表中)。证书的日期也可能过期。使用 HTTPS 时,TLS 用于身份验证。客户端指定要使用的 TLS 版本,服务器发送一个证书块,其中包含可以使用的证书名称列表。客户端然后查找证书的名称以找到要使用的证书。客户端还必须能够支持证书的加密模式。最好使用 Net 4.7.2 并使用操作系统进行 TLS。
-
谢谢@jdweng。我正在使用 .NET Core 3.1,因为这是 VS2019 在我创建项目时为我选择的(现在大约 9 个月前)。我应该升级吗?如果是这样,怎么做?为什么这会发生在我想要运行服务器的一台机器上,但在我的正常开发机器上却从未发生过?
-
Core 3.1 有很多错误。最新下载:dotnet.microsoft.com/download/dotnet/3.1左栏是你用来编译的,右栏是安装在部署机器上的运行时间
-
好的,我已经安装了这些更新......仍然没有区别。 :(
-
我如何确保证书在机器和用户存储中? (我如何检查?)如果它已过期,我该如何解决?我如何告诉它使用操作系统进行 TLS?
标签: c# asp.net-core ssl kestrel-http-server