Asp.net

如何配置 ASP.NET Core 1.0 以使用本地 IIS 而不是 IIS Express?

  • July 27, 2016

調試時如何設置**.Net Core 1.0項目以使用本地 IIS而不是IIS Express**?

我嘗試過以各種方式修改launchSettings.json文件。例如,將所有出現的IIS Express替換為本地 IIS並更新applicationUrllaunchUrl以使用我的自定義 localhost <http://sample.local>(我已經更新了主機文件並配置了 IIS 管理器)但不滿意。

Properties/launchSettings.json文件的預設設置:

{
 "iisSettings": {
   "windowsAuthentication": false,
   "anonymousAuthentication": true,
   "iisExpress": {
     "applicationUrl": "http://localhost:38601/",
     "sslPort": 0
   }
 },
 "profiles": {
   "IIS Express": {
     "commandName": "IISExpress",
     "launchBrowser": true,
     "environmentVariables": {
       "ASPNETCORE_ENVIRONMENT": "Development"
     }
   },
   "SampleApp": {
     "commandName": "Project",
     "launchBrowser": true,
     "launchUrl": "http://localhost:5000",
     "environmentVariables": {
       "ASPNETCORE_ENVIRONMENT": "Development"
     }
   }
 }
}

您目前無法在開發時直接使用 IIS 來託管 ASP.NET Core 應用程序,因為開發文件夾不提供 IIS 需要託管的所有必要文件。這使得在開發環境中執行 ASP.NET Core有點痛苦。

正如Rick Strahl 在這篇文章中所指出的,嘗試這樣做的理由並不多。IIS 在執行 ASP.NET Core 應用程序時做的很少——事實上,您的應用程序不再直接在 IIS 程序中執行,而是在託管 Kestrel Web 伺服器的完全獨立的控制台應用程序中執行。因此,當您自行託管控制台應用程序時,您實際上是在基本相同的環境中執行。

如果確實需要發布應用,可以使用dotnet命令行或使用 Visual Studio 工具將應用發佈到本地文件夾。

例如,如果要發佈到C:\output文件夾,可以使用以下命令:

dotnet publish
 --framework netcoreapp1.0 
 --output "c:\temp\AlbumViewerWeb" 
 --configuration Release

然後,您可以將 IIS 站點指向輸出文件夾。確保將應用程序池 CLR 版本設置為無託管程式碼並且AspNetCoreModule可用。

有關詳細資訊,請參閱<https://docs.asp.net/en/latest/publishing/iis.html>

引用自:https://stackoverflow.com/questions/38619454