Publish an ASP.NET Core application for Azure through PowerShell receiving 502 (Bad Gateway) in Azure

How can I publish an ASP.NET Core app for Azure?

What I have done so far is a script that I got from the official Azure / Microsoft docs that call the default-publish.ps1 script that Visual Studio uses. The script looks like this:

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 default-publish.ps1 script, given that you specify the Azure site name and the dotnet publish artifact. I updated my default-publish.ps1 script exactly what is in the repo right now.

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

+8
powershell asp.net-core azure
source share
1 answer

Do you have web.config? Is it included in your .json project 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 problem. You are trying to run publishing scripts that run in visual studio, it is possible that visual studio sets the values ​​in the environment before running the scripts.

In order to get the RC2 site and run on Azure VM, I had to change this line to look like this:

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

Try setting your web.config with explicit values. If your deployment works, then you know its missing ENVVARS, which confuse it.

+1
source share

All Articles