Search code examples
asp.netajaxdockeramazon-elastic-beanstalkamazon-linux-2

AJAX requests failing for ASP.NET Core app in Amazon Linux 2 vs Amazon Linux 1


I have an ASP.NET Core v.3.0 web application hosted in Amazon AWS Elastic Beanstalk using Docker. The application works fine in Docker running 64bit Amazon Linux (v2.16.11). When I update to Docker running 64bit Amazon Linux 2 (v3.4.12) the requests work fine except for AJAX requests which fail with Status Code Error 400 "Bad request". Nothing else has changed in the source code, dockerfile etc. Only the Linux version has changed from Amazon Linux to Amazon Linux 2. Does anybody have an idea what is different between Amazon Linux 1 and Amazon Linux 2 that may be the cause leading to AJAX requests failing?

More info:

  1. I cannot replicate this error with the official ASP.NET core 3.1 examples. I have not updated my application to v3.1, I will do it soon and I will update this question.
  2. The relevant action inside the controller does not return the partial view in Amazon Linux 2. The controller provides a log just before returning the partial view and this is not triggered in Amazon Linux 2.
  3. The nginx access.log file shows the following response of the load balancer:

Amazon Linux 1: {IP} - - [10/Apr/2022:07:36:01 +0000] "POST {url} HTTP/1.1" 200 3882 "{url2}" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36" "{IP2}"

Amazon Linux 2: {IP} - - [10/Apr/2022:07:00:14 +0000] "POST {url} HTTP/1.1" 400 0 "{url2}" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36" "{IP2}"

  1. The call is made with jQuery 3.4.1:

    var $form = $("#inputForm");
    if ($form.length <= 0) return;
    var data = $form.serialize();
    $.ajax({
        url: "...",
        type: "POST",
        data: data,
        error: function (jqXHR, textStatus, errorThrown) {
            alert("There was an error when loading the results (error type = " + errorThrown + ").");
        },
        success: function (result) {
            $("#calculationTarget").html(result)
        });
    

Solution

  • The issue is no longer present if the project is updated from ASP.NET Core 3.0 to ASP.NET Core 3.1.