Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing ASP.NET Core application to Azure via PowerShell getting 502 (Bad Gateway) In Azure

How can I publish my ASP.NET Core application to Azure?

What I have done so far is created a script that I got from official Azure/Microsoft documents that call on default-publish.ps1 script that Visual Studio also uses. The script looks as follows:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]


$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}


$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"


. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

Now this script calls upon the default-publish.ps1 script, given you provide the Azure website name and the dotnet publish artifact. I have updated my default-publish.ps1 script to exactly what is currently in the repo.

The issue is that when I publish to Azure a 502 Bad Gateway error is returned. Even with a project created using the new tooling update, I cannot seem to publish it to Azure correctly.

like image 924
Lutando Avatar asked May 24 '16 13:05

Lutando


1 Answers

Do you have a web.config? Is it included in your project.json like this:

"publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  }

Your web.config will look something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" 
           resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" 
                stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"  
                forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

Note: The environment variables LAUNCHER_PATH and LAUNCHER_ARGS may be the source of your issue. You are attempting to launch the publishing scripts that visual studio runs, it is possible that visual studio sets the values in the environment before running the scripts.

To get an RC2 site up and running on an Azure VM, I had to change that line to look like this:

<aspNetCore processPath="dotnet" arguments="./YourAppEntryPoint.dll" 
            stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" 
            forwardWindowsAuthToken="false"/>

Try setting your web.config with the explicit values. If your deploy works, then you know it's the missing ENVVARS that are messing it up.

like image 85
NotMyself Avatar answered Sep 24 '22 08:09

NotMyself