28

I'm trying to publish to IIS a .NET Core ASP.NET Website I upgraded from RC2 to RTM.

As a sanity check, I was successfully able to publish the template/sample "ASP.NET Core Web Application (.NET Framework)" app from Visual Studio 2015.

But for some reason, when publishing the RTM upgraded app, I'm getting HTTP Error 502.3 - Bad Gateway The specified CGI application encountered an error and the server terminated the process.

The site DOES work running IIS Express from Visual Studio.

How can I debug this? Anyone have any ideas?

Error 502.3

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath=".\MyApp.exe" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

project.json

{
  "buildOptions": {
  "emitEntryPoint": true,
  "preserveCompilationContext": true,
  "warningsAsErrors": true
},
"dependencies": {
  "Microsoft.AspNetCore.Diagnostics.Elm": "0.1.0",
  "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
  "Microsoft.AspNetCore.Authorization": "1.0.0",
  "Microsoft.AspNetCore.Diagnostics": "1.0.0",
  "Microsoft.AspNetCore.Hosting": "1.0.0",
  "Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0",
  "Microsoft.AspNetCore.Http.Extensions": "1.0.0",
  "Microsoft.AspNetCore.Localization": "1.0.0",
  "Microsoft.AspNetCore.Mvc": "1.0.0",
  "Microsoft.AspNetCore.Routing": "1.0.0",
  "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
  "Microsoft.AspNetCore.Session": "1.0.0",
  "Microsoft.AspNetCore.StaticFiles": "1.0.0",
  "Microsoft.Extensions.Caching.SqlServer": "1.0.0",
  "Microsoft.Extensions.Logging.Console": "1.0.0",
  "Microsoft.Extensions.Logging.Debug": "1.0.0",
  "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",

  "Microsoft.AspNetCore.Razor.Tools": {
    "version": "1.0.0-preview2-final",
    "type": "build"
  },

  "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
  "Microsoft.Extensions.Configuration.Json": "1.0.0",
  "Microsoft.Extensions.Logging": "1.0.0",
  "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},

"frameworks": {
   "net461": {}
 },

"tools": {
  "BundlerMinifier.Core": "2.0.238",
  "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
  "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},

"scripts": {
  "prepublish": [ "bower install", "dotnet bundle" ],
  "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
},

"publishOptions": {
  "include": [
    "wwwroot",
    "web.config",
    "appsettings.json",
    "**/*.cshtml",
    "Config/*.json"
    ]
  ]
 }
}
user247702
  • 23,641
  • 15
  • 110
  • 157
John-Luke Laue
  • 3,736
  • 3
  • 32
  • 60
  • This happened to me on a .NET Core Web project when I added "Microsoft.Extensions.Configuration.Json" and then it worked again as soon as I removed it. I don't know why unfortunately. – lala Apr 14 '21 at 18:37

5 Answers5

17

If you run a task for a long time, and web browser don't receives response in 2 mins(the default request time), you'll get this error. Because after the timeout, IIS will replaces the application to respond to the client with 'Bad Gateway'.

Maybe you should change the request time in the web.config.

Set requestTimeout attribute in section system.webServer / aspNetCore to specifies the duration for which the ASP.NET Core Module will wait for a response from the process listening on %ASPNETCORE_PORT%.

  • The requestTimeout must be specified in whole minutes only, otherwise it defaults to 2 minutes.

Just like this:

<system.webServer>
  <aspNetCore requestTimeout="00:20:00" ... />
</system.webServer>
zmjack
  • 171
  • 1
  • 5
15

How can I debug this? Anyone have any ideas?

Here are three ideas:

  1. Read this and make sure that you have covered all that it says.

  2. Run the published .\MyApp.exe from the command line. Does that work?

    • If it does, you know you have an IIS integration problem.
    • If it does not, you know you have an application problem.
  3. Change stdoutLogEnabled="false" to true and then check the logs at stdoutLogFile=".\logs\stdout". The error(s) there might tell you something.

  4. Check your IIS Application logs in the Event Viewer. The error(s) there might tell you something.

Event Viewer Application Logs

Event Viewer Application Logs

Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
  • 2
    thanks so much! I was able to get the log file and it turns out the app's hosting environment was set to Production and it was failing on the login to the production sql server. Quick question: how do you tell which environment the deployed app should use? – John-Luke Laue Sep 28 '16 at 21:57
  • @johnluke-laue Set an environmental variable. See http://stackoverflow.com/questions/28258227/how-to-set-ihostingenvironment-environmentname-in-vnext-application/30314719#30314719 – Shaun Luttin Sep 28 '16 at 22:00
  • I create the folder .\logs , but the log files are empty, I don't know why. – mejiamanuel57 Oct 27 '17 at 01:57
  • 1
    Step 3, the event logs, helped me find this URL solution of HttpPlatformHandler version 1.2 - https://stackoverflow.com/questions/33255222/running-mvc-6-beta-8-application-on-iis – Daniel Jackson May 30 '18 at 15:27
  • In my case the reason was duplicit tag in web.config. Hate ASP.NET and it's error reporting! – Karel Kral Aug 03 '18 at 14:48
  • @mejiamanuel57, probably process has not access rights to create file in this folder. You have explicitly assign rights. – Karel Kral Aug 03 '18 at 14:50
  • 2
    @KarelKral Thank you for pointing a possible issue. In my case a problem was with web.config environmentVariable section, where :xdt:Transform="Replace" xdt:Locator="Match(name)" was added to the 'environmentVariable '. When I removed it, everything started to work. – Stivin May 06 '20 at 14:13
4

The solutions did not work for me, but what did is:

Enable web developer mode (press F12 in your browser)=> application tab =>then remove all cookies. Refresh the page and voilà: it works. Also you can copy your URL and paste to another browser you haven't run any MVC project.

My project worked on Internet Explorer and Microsoft Edge without any change. Perhaps that's the cause of your error.

Iman
  • 17,932
  • 6
  • 80
  • 90
  • Thanks a lot. after trying to repair and reinstall all sort of core and runtime SDKs and .NET framework. removing website cookie worked. You can also check it fast by running it inside incongnito mode in chrome. – Iman Oct 22 '19 at 10:45
0

Not directly an answer to the OP's specific instance of this 502.3 error, but it also can occur if there is an infinite loop, as I accidentally left in my application:

public class Category
{
    public Category()
    {
        ParentCategory = new Category();
    }

    Category ParentCategory { get; set; }
}

There was no clear error indicating that this was the issue. Hope it helps someone.

Graham Meehan
  • 445
  • 5
  • 18
0

One possible cause is, there is some exception after the return statement from your API. In my case, there was a circular reference in the object that I was returning in an IActionResult. While debugging, I converted the object being returned into JSON format, using Newtonsoft.Json.JsonConvert.SerializeObject(). This resulted in following exception being returned from the API endpoint:

Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'xxx' with type 'xxx'. Path 'xxx'.? at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)

Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32