Bad gateway Error in Ajax call HTTP Error 502.3 - Bad Gateway

  • Thread starter Thread starter rejeesh nv
  • Start date Start date
R

rejeesh nv

Guest
Hi

I am working on an application which uses Angular js and Dotnet core mainly. For one reporting functionality we are using Ajax call to call MVC controller for generating Excel output. File will be generated by the console application. In normal cases it works fine but problem is that when execution takes more time as the logic involves many iterations and procedures we are getting a client side exception and user is not able to download the generated excel. Below is the error log which i got in ajax error handler

HTTP Error 502.3 - Bad Gateway

The specified CGI application encountered an error and the server terminated the process.

Most likely causes:


  • The CGI application did not return a valid set of HTTP errors.
  • A server acting as a proxy or gateway was unable to process the request due to an error in a parent gateway.

This error mainly occurs when the internet connection is comparatively low and processing of excel creation takes more time for some cases


Ajax call code is something similiar to this


$.ajax({
beforeSend: function (xhr) {
if (showProgress === undefined || showProgress)
$(".grid-msg-overlay").show();
},
complete: function () {
if (showProgress === undefined || showProgress)
$(".grid-msg-overlay").fadeOut(10);
},
type: type,
url: URL,
data: param,
injection: injection,
contentType: contentType,
async: isAsync,
dataType: 'json',
success: function (response, textStatus, request) {
if (typeof successCallback === 'function')
successCallback(response, this.injection);
},
error: function (Response, XMLHttpRequest, textStatus, errorThrown) {
if (typeof errorCallback === 'function')
errorCallback(Response, XMLHttpRequest, textStatus, errorThrown);
}
});


server side code is something like this

[Route("[action]")]
[ResponseCache(Duration = 0)]
public async Task<ActionResult> ExcelExport(int SurveyId, string TerritoryId)
{

---------------------------

Excel.Workbook MyBook = null;

MyApp = new Excel.Application(); // for creating excel sheet interop

---------------------------

-------------------------------

--------------------------

return json;

}



Here when this particular exception is happening for long processing of excel data its getting thrown to ajax error handler as Bad gateway 503 error. But there is no execution failure from the server side and excel processing will be successfully completed after few seconds. So here our technical challenge is in this particular case is that the Ajax success handler will not be called and user is not aware that excel is generated and will not get message box for downloading excel. So there is no way to intimate user that excel exporting is done and message box to download file in the client side because of that unknown exception thrown to client side. We have tried several methods but none of them didn't give positive result.

So what can be done to handle this error. I tried to change the time out property of CGI application in IIS and its also having no effect. Please help me to resolve this error. Expecting a solution at the earliest


Thanks

Rejeesh

Continue reading...
 
Back
Top