ASP.NET Core app not working after publish to Azure

前端 未结 1 1469
天命终不由人
天命终不由人 2021-01-05 23:05

I have an ASP.NET Core app which is running fine locally.

However, when I publish (Web Deploy) the site to Azure, I get a 403:

1条回答
  •  无人及你
    2021-01-06 00:03

    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:

    
      
        
          
        
        
      
    
    

    Finally I added UseIISIntegration to my WebHostBuilder:

    public static void Main(string[] args)
    {
       new WebHostBuilder()
          .UseKestrel()
          .UseContentRoot(Directory.GetCurrentDirectory())
          .UseStartup()
          .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).

    0 讨论(0)
提交回复
热议问题