我需要调试外部身份验证,它需要HTTPS。同时对于大多数内部请求http就足够了。在IIS上托管我的Web应用程序时,在80和443端口上监听没有问题,但是我看到Kesterl托管的ASP.NET Core,端口严格绑定到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"
}
我很好奇,是否有可能一次在两个端口上都有监听器而无需在其他配置中重新启动以更改协议。
According to the documentation您可以在同一配置中定义端点:
"localCalls": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000;https://localhost:5100"
}
}
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
文件。我希望有所帮助