Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core RC2 IIS returning 502 on options request

We have a ASP.NET Core application that we recently upgraded to RC2. Before the upgrade everything was fine, and after the upgrade everything works in the Dev and Staging environments, but in Production, the app responds with 502 to every request that is not handled by an MVC endpoint:

502 - Web server received an invalid response while acting as a gateway or proxy server. There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

This means that for instance https://www.myapp.com/somenonexistingroute returns 502 rather than 404, while calls to existing endpoints work fine.

The problem is that we are using the app in a cross origin context, so we need options requests (preflight cors requests) to work, and they also respond with a 502.

All environments are running Windows Server 2012 with IIS 8.5 and the ASP.NET Core platform handler installed.

What is going on?

Update

After some more debugging we discovered that this is probably caused by a bug in the framework. We have created a GitHub issue

like image 639
severin Avatar asked Nov 20 '22 04:11

severin


1 Answers

I know it's late to help, but maybe it helps some other people who face this kind of issue.

I had too a 502 error for preflight requests (option request, angular 5 website -> asp.net core 2.0 web api, iis 7.5).

I found out that I defined twice the ASPNETCORE_ENVIRONMENT environment variable (with the same value); once in the web.config file of my asp.net core web api, and once in the configuration editor of IIS (system.webServer/aspNetCore -> ApplicationHost.config <…> -> enviromentVariables). As soon as I removed one of them (the IIS one, but whichever would work), my preflight requests worked again!

like image 64
Aymen Turki Avatar answered Dec 14 '22 18:12

Aymen Turki