.NET6开发时支持IIS

操作步骤

  1. 下载dotnet-hosting-6.0.0-rc.1.21452.15-win.exe并安装,成功后检查IIS模块中是否有AspNetCoreModuleV2
  2. 安装VS时选择“开发时IIS支持”
  3. 在IIS中创建站点,目录指向开发项目wwwroot的上级目录,应用程序池默认与站点名称相同
  4. 将刚新建站点的应用程序池的.NET CLR版本改成无托管代码
  5. 在项目启动配置文件中添加配置(也可在项目属性调试中配置)
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://xxx.xxxx.com",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS": {
      "commandName": "IIS",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
  1. 在项目中添加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>