可以在 Kestrel 和 .NET Core 中调试 HTTP 和 HTTPS,就像在 IIS 下的 .Net 4.x 中一样
Possibility to debug both HTTP and HTTPS in Kestrel and .NET Core like in .Net 4.x under IIS
我需要调试外部身份验证,它需要 HTTPS。同时对于大部分内部请求http就足够了。在 IIS 上托管我的 Web 应用程序时,监听 80 和 443 端口没有问题,但是我看到 ASP.NET Core 由 Kesterl 托管,该端口严格绑定到 launchSettings.json 中的特定配置,例如如:
"localCalls": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:40000"
},
"externalIdentity": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:50000"
}
我很好奇,是否可以同时在两个端口上都有侦听器,而无需在其他配置中重新启动以更改协议。
Asp.Net Core 2.1 及更高版本使使用本地 SSL 变得超级容易。当您使用 Visual Studio 创建项目时,它会询问您是否需要启用 SSL。如果您在创建项目之前选择了该选项,您应该会看到如下所示的 launchSettings.json 文件:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61110",
"sslPort": 44377
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"YourProjectName": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
iisSettings
部分用于 IISExpress,其中定义了 sslPort
,即在本例中为 44377。因此,当您的项目在 IISExpress 下运行时,它会使用该设置
YourProjectName
部分适用于 Kestrel。您可以看到 applicationUrl
同时使用了 http
和 https
端点。所以当你做 dotnet run
你应该看到
Hosting environment: Development
Content root path: C:\users\...\YourProjectName
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
此外,在Configure
方法下,你应该看到下面一行,所以它会自动将HTTP重定向到HTTPS
app.UseHttpsRedirection();
如果您的 launchSettings.json
文件与上面的不一样。尝试在项目属性中更改它并启用 SSL,如下面的屏幕截图所示。当您保存设置时,launchSettings.json
文件将被更新
如果上述方法不起作用,请尝试手动更改 launchSettings.json
文件。希望对您有所帮助
According to the documentation 您可以在同一配置中定义端点:
"localCalls": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000;https://localhost:5100"
}
}
我需要调试外部身份验证,它需要 HTTPS。同时对于大部分内部请求http就足够了。在 IIS 上托管我的 Web 应用程序时,监听 80 和 443 端口没有问题,但是我看到 ASP.NET Core 由 Kesterl 托管,该端口严格绑定到 launchSettings.json 中的特定配置,例如如:
"localCalls": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:40000"
},
"externalIdentity": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:50000"
}
我很好奇,是否可以同时在两个端口上都有侦听器,而无需在其他配置中重新启动以更改协议。
Asp.Net Core 2.1 及更高版本使使用本地 SSL 变得超级容易。当您使用 Visual Studio 创建项目时,它会询问您是否需要启用 SSL。如果您在创建项目之前选择了该选项,您应该会看到如下所示的 launchSettings.json 文件:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61110",
"sslPort": 44377
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"YourProjectName": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
iisSettings
部分用于 IISExpress,其中定义了 sslPort
,即在本例中为 44377。因此,当您的项目在 IISExpress 下运行时,它会使用该设置
YourProjectName
部分适用于 Kestrel。您可以看到 applicationUrl
同时使用了 http
和 https
端点。所以当你做 dotnet run
你应该看到
Hosting environment: Development
Content root path: C:\users\...\YourProjectName
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
此外,在Configure
方法下,你应该看到下面一行,所以它会自动将HTTP重定向到HTTPS
app.UseHttpsRedirection();
如果您的 launchSettings.json
文件与上面的不一样。尝试在项目属性中更改它并启用 SSL,如下面的屏幕截图所示。当您保存设置时,launchSettings.json
文件将被更新
如果上述方法不起作用,请尝试手动更改 launchSettings.json
文件。希望对您有所帮助
According to the documentation 您可以在同一配置中定义端点:
"localCalls": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000;https://localhost:5100"
}
}