TL; DR今天使用ASP.NET Core 2.0设置HTTPS的正确方法是什么?
我想将我的项目配置为使用https和他们在BUILD 2017中展示的证书.我尝试了几个设置,但没有任何效果.经过一番研究,我更加困惑.看来,有很多方法可以配置URL和端口.我已经看到了appsettings.json,hosting.json通过代码,在launchsettings.json我们还可以设置URL和端口.
有"标准"的方法吗?
这是我的 appsettings.development.json
{
"Kestrel": {
"Endpoints": {
"Localhost": {
"Address": "127.0.0.1",
"Port": "40000"
},
"LocalhostWithHttps": {
"Address": "127.0.0.1",
"Port": "40001",
"Certificate": {
"HTTPS": {
"Source": "Store",
"StoreLocation": "LocalMachine",
"StoreName": "My",
"Subject": "CN=localhost",
"AllowInvalid": true
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是launchsettings.json当我从命令行dotnet run开始或从Visual Studio开始使用调试器时,它始终需要url和port .
这是我Program.cs和Startup.cs
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public …Run Code Online (Sandbox Code Playgroud) 我开发了一个基于 ASP.NET Core 的 Angular 应用程序,并且有一些设置以便使用launchSettings.json给定端口运行该应用程序,如下所示:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
},
"EmployeeProject.WebUI": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:6000;https://localhost:6001",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我听说在使用VS Code时以及在每次运行时使用随机端口启动应用程序同时运行前端和后端时,这些设置将被忽略。那么,如何让应用程序通过VS Code或在 VS Code 中使用相同的端口(6000 或 6001)启动?dotnet watch rundotnet rundotnet watch run