ASP.NET Core app not working after publish to Azure

只愿长相守 提交于 2019-11-30 21:22:22

The problem came from insufficient IIS integration/configuration.

I had to add the following to project.json:

"tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  }

I also added a postPublish script for IIS publishing:

"scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }

I also added the Microsoft.AspNetCore.Server.IISIntegration NuGet package:

"dependencies": {
  "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0"
}

This created a web.config file, which I had to modify as:

<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\My.Web.App.dll" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
  </system.webServer>
</configuration>

Finally I added UseIISIntegration to my WebHostBuilder:

public static void Main(string[] args)
{
   new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .UseIISIntegration() // This was missing
      .Build()
      .Run();
   }

A standard Publish (Web Deploy) from Visual Studio and the website started just fine on Azure (although in my case I also had to add a prepublish script for some Gulp tasks).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!