IIS 10 AJAX not working for dotnet core 5 MVC

Viewed 463

I am writing an asp dot net core MVC application. Here I am using a GET AJAX call. When I am running my application from Visual Studio it works without any issue. But after deploying to my local IIS 10 server my AJAX call is giving me below error message.

Any help or suggestions why on IIS this is happening?

 GET http://mycrt.geotab/GitLab/GetRackStatus 500 (Internal Server Error)    jquery.js:10099

Here is my AJAX call

$('#rackInfo').click(function () {
    var url = 'GitLab/GetRackStatus'; //http://mycrt.geotab/GitLab/GetRackStatus URL also returns same error
    $.blockUI();
    $.ajax({
        url: url,
        type: "GET",
        success: function (responseHtml) {
            $('#rackInfoResults').replaceWith(responseHtml);
            $('#rackInfoResultsError').hide();
            bindEventsOnRacks();
            $.unblockUI();
        },
        error: function (responseHtml) {
            $('#rackInfoResults').hide();
            $('#rackInfoResultsError').show();
            $.unblockUI();
        }
    });           
});

Here is my controller

public async Task<IActionResult> GetRackStatus()
{
  //Controller code
  return PartialView("_RackStatusPartialView");
}

Here is my launchSettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:53400",
      "sslPort": 44339
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyCRT": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": "true",
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
      "publishAllPorts": true,
      "useSSL": true
    }
  }
}

Note: I have tried with below URL in AJAX, and that Gives me below error

http://localhost/GitLab/GetRackStatus
Access to XMLHttpRequest at 'http://localhost/GitLab/GetRackStatus' from origin 'http://mycrt.geotab' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Failed to load resource: net::ERR_FAILED

Here is my IIS profile

enter image description here

1 Answers

This can happen for several issues.

  1. Check the DB connection is ok for your IIS server code.
  2. Check the permission about your folder if u retrieve any file or data from the specific folder.
  3. check the validation of your URL that you are posting by ajax to your controller that it post the valid data to the controller and the incoming response is valid too.
Related