使.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"
      }
    }
  }
}

6.在項目中添加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>

到此這篇關於使.NET6在開發時支持IIS的文章就介紹到這瞭。希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。

推薦閱讀: