none
Bad gateway Error in Ajax call HTTP Error 502.3 - Bad Gateway RRS feed

  • Question

  • 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 

    Friday, July 27, 2018 3:54 PM

All replies

  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/df14dc5f-982b-4676-b767-6123c8a90495/where-is-the-correct-place-to-make-posts-regarding-aspnet-mvc-webapi-and-core-sql-or-another?forum=csharpgeneral

    The C# forum is the wrong forum to post with your  issues concerning Web development.

    Friday, July 27, 2018 9:38 PM
  • Hi rejeeesh nv,

    Thank you for posting here.

    Since your question is more related to MVC, you could post a new thread in MVC forum for suitable support.

    https://forums.asp.net/1146.aspx/

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 30, 2018 6:04 AM