自托管的ASP.NET Core应用程序不适用于SSL [英] Self hosted ASP.NET Core app does not work with SSL
问题描述
我已经使用命令行创建了示例ASP.NET Core
应用程序:
I have created an sample ASP.NET Core
application using command line:
dotnet new
并尝试使用命令运行它:
and tried to run it utilizing command:
dotnet run
但是,当在浏览器中打开URL时,它抱怨SSL无效.
But, when opening the URL in the browser, it complains that the SSL is invalid.
我可以使用Visual Studio
完整版运行程序,没有任何问题,但是不能使用命令行运行它:
I can run the program using Visual Studio
full version without any problem, but can not run it using command line:
dotnet run
似乎由命令dotnet run
运行的Kestrel
需要额外的配置.
Seems that Kestrel
which is run by command dotnet run
needs extra configurations.
现在,问题是如何使用Kestrel
在https
上运行ASP.NET Core
应用程序?
Now, the question is how can I run my ASP.NET Core
application over https
using Kestrel
?
我在Dot Net Core 2.2
和Visual Studio 2019
推荐答案
在使用dotnet run
或在Visual Studio中以开发模式运行ASP.NET Core时,已经内置了对开发证书的支持.允许您立即使用HTTPS支持进行开发.
When you run ASP.NET Core in development mode using dotnet run
, or from within Visual Studio, then there is already built-in support for a development certificate that allows you to develop right away with HTTPS support.
开发证书是.NET Core SDK内置的,通常,当您第一次运行.NET Core SDK时,它应该自行设置.如果这样不起作用,或者由于某种原因您丢失了开发证书,那么以后可以随时使用以下命令来安装它:
The development certificate is built-in with the .NET Core SDK and usually it should set it self up when you run the .NET Core SDK for the first time. If that did not work or if you lost the development certificate for some reason, then you can always install it later using the following command:
dotnet dev-certs https --trust
请注意,开发证书仅在开发期间适用,当然您需要为以后的生产设置适当的证书.当然,如何工作取决于您以后如何托管应用程序.
Note that the development certicate only applies during development and of course you will need to set up a proper certificate for production later. How that works of course depends on how you are going to host the application later. The different options and how to configure SSL is covered in the hosting chapter.
这篇关于自托管的ASP.NET Core应用程序不适用于SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!