skip to Main Content

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)
        });
    

2

Answers


  1. Chosen as BEST ANSWER

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


  2. There is a very simple fix, which is updating to ASP.NET Core 3.1.

    In this version, the issue that you have having is fixed.


    See the steps below for updating.

    1. If you have a global.json file to target a specific .NET Core SDK version, update the version property.

      {
        "sdk": {
          "version": "3.1.101"
        }
      }
      
    2. Update the TFM to netcoreapp3.1, as described below.

      <Project Sdk="Microsoft.NET.Sdk.Web">
        <PropertyGroup>
          <TargetFramework>netcoreapp3.1</TargetFramework>
        </PropertyGroup>
      </Project>
      
    3. You need to update the package references. To do this, update every Microsoft.AspNetCore.* (* meaning wildcard) to 3.1.0 (or any version later).

    4. If you are using Docker (which I think you are), then you need to use an ASP.NET Core 3.1 base image. See an example below.

      $ docker pull mcr.microsoft.com/dotnet/aspnet:3.1
      

    For extra steps and information, see the official guide from migrating to ASP.NET Core 3.1.


    In summary, upgrading your current application to ASP.NET Core 3.1 should fix your issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search