一、launchSetting.json
打开launchSetting.json文件后,默认情况下,如下面代码所示:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55589",
"sslPort": 44322
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication1": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
在profiles节点处有两个子节点:“IIS Express”和“WebApplication1”,这两个子节点分别对应VS中的两种启动方式。
值得一提的是,commandName 属性的值可以是以下三个中的任何一个:
- IISExpress
- IIS
- Project
以下lunchSetting.json文件中包含多个配置文件
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64645",
"sslPort": 44366
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IISX-Production": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},
"IISX-Staging": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging",
"ASPNETCORE_DETAILEDERRORS": "1",
"ASPNETCORE_SHUTDOWNTIMEOUTSECONDS": "3"
}
},
"EnvironmentsSample": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"KestrelStaging": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
}
}
}
}
二、AspNetCoreHostingModel
这个属性是项目文件(.csproj)中的一个节点。这个属性值只有两个:InProcess和OutOfProcess。
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<!--<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>-->
</PropertyGroup>
</Project>
默认条件下,项目文件中不会配置该属性,则默认为InProcess。
三、内部和外部服务器
上述两个配置决定了内部和外部Web服务器,具体如下:
CommandName(启动方式) | AspNetCoreHostingModel | Internal Web Server External Web Server |
---|---|---|
Porject | ignore | 仅使用一台Web服务器–Kestrel |
IIS Express | InProcess | 仅使用一台Web服务器–IIS Express |
IIS Express | OutOfProcess | Kestrel IIS Express |
IIS | InProcess | 仅使用一台Web服务器–IIS |
IIS | OutOfProcess | Kestrel IIS |