操作步驟
- 下載dotnet-hosting-6.0.0-rc.1.21452.15-win.exe並安裝,成功后檢查IIS模塊中是否有AspNetCoreModuleV2
- 安裝VS時選擇“開發時IIS支持”
- 在IIS中創建站點,目錄指向開發項目wwwroot的上級目錄,應用程序池默認與站點名稱相同
- 將剛新建站點的應用程序池的.NET CLR版本改成無托管代碼
- 在項目啟動配置文件中添加配置(也可在項目屬性調試中配置)
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://xxx.xxxx.com",
"sslPort": 0
}
},
"profiles": {
"IIS": {
"commandName": "IIS",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
- 在項目中添加web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="bin\Debug\net6.0\Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" arguments="">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>