Search code examples
jqueryasp.netajaxasp.net-mvcepiserver

Asp.NET action method succeeds but browser receives a 500 with jQuery.ajax


I have a page that makes an AJAX request to update a small pricing section on the page. It works properly when running on my local machine, but when published to our development server, the AJAX call receives a Internal Server Error 500 response. The part that I get lost at is when I attach the debugger and step through the code, the action appears to complete successfully so it seems something happens after the action method runs that causes the 500 but I don't know of any code that runs after the action method.

Here is the .js ajax, the action method, and its response:

_paymentPlanXhr = $.ajax({
            type: "POST",
            url: $("#_Booking_UpdatePaymentUrl").val(),
            data: "purchaseMem="+ purchaseMem +"&sid=" + selectedStudentID,
            cache: false,
            dataType: "json",
            timeout: 120000,
            success: function (response) {
                ...
            },
            error: function (jqXHR, textStatus, errorThrow) {
                _paymentPlanXhr = null;
                $loadingDiv.hide();
                _pendingPaymentPlanUpdate = false;

                //If this was really an error, not the result of our code cancelling the request
                if (textStatus != "abort")
                    $("#divPaymentLoadError").show();
            }
        });

Action Method:

    [HttpPost]
    public ContentResult Booking_UpdatePayment(PsnBookingPage currentPage, bool purchaseMem, Guid sid)
    {
        AjaxResponse result = new AjaxResponse();
        BookingViewModel bookingVM = new BookingViewModel();


        try
        {
            //Code for building the vm omitted for brevity since it succeeds.

            result.Content = this.RenderPartialView(_paymentViewUrl, viewModel, true);
        }
        catch (Exception ex)
        {
            viewModel.AbortView = true;
            viewModel.AbortMessage = "We're sorry! Something went wrong and we were unable to load the view.";
        }

        return result.ToContentResult();
    }

result.ToContentResult:

{"HasError":false,"ErrorMessage":null,"Content":"      <div id=\"divSelectDate\"><div class=\"data-price\">Due Today: $20.00</div><div class=\"data-price\">Due on Event Date: $0.00</div></div>","Data":null}

I don't know if it's a factor, but this is an EPiServer-based site. How can I find the source of the 500?

Edit:

Maybe this is related to EPiServer because even though I have custom errors turned off, the response I get with the 500 has the following instead of the yellow asp.net error screen:

<html>
<head>
    <meta name="robots" content="noindex,nofollow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>
        Page could not be loaded
    </title>
    <style type="text/css">
        body{font-size:65%;color:black;background-color:White;}
        form{font-size:1.2em;}
        body,table{font-family:Verdana;font-weight:normal;}
        h1{color: gray;font-size: 1.4em;font-family:Verdana;margin:0.5em 0 0 0;}
        h2{font-size:1.2em;font-weight:bold;}
        h3{display: inline;font-weight:bold;font-size: 1.0em;}
        .ExceptionInfo{margin:0.6em 0 0.6em 0.2em;}
        .StackTrace{font-family:"Lucida Console";}
        th{font-size: 0.8em;text-align:left;white-space: nowrap;}
        td{font-size: 0.7em;}
        .DetailedHeader{font-weight:bold;border: 1px solid black;padding:4px;text-align:center;}
        .ReportForm{font-family:Verdana;font-weight:normal;font-size: 1.0em;color:black;}
        .SubmitButton{font-family:Verdana;font-weight:normal;font-size: 1.0em;color:black;}
    </style>
    <script type="text/javascript">
        <!--
        function onNavigate(newPageLink)
        {
            return -1;
        }

        function onCommand(newCommand)
        {
            return -1;
        }
        // -->
    </script>
</head><body>
    <h1 class="Title">
        Page could not be loaded

    </h1><p style="width:40em;">The link you specified does not work. This may either be the result of temporary maintenance or an incorrect link.
    </p></body></html>

I thought this was a chrome page, but another thread suggests its an EPiServer-generated page.


Solution

  • You're looking for the globalErrorHandling attribute on the applicationSettings element in episerver section of web.config (or episerver.config).

    Read more about it here: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/75/Configuration/Configuring-episerver/

    It could also be on the site element if you're using EPiServer 7 or earlier.