IIS 10 AJAX 不适用于 dotnet core 5 MVC

IIS 10 AJAX not working for dotnet core 5 MVC

我正在编写一个 asp 点网核心 MVC 应用程序。我在这里使用 GET AJAX 调用。 当我 运行 我的应用程序来自 Visual Studio 时,它可以正常工作。 但是在部署到我的本地 IIS 10 服务器后,我的 AJAX 调用正在提供我在错误消息下方。

为什么在 IIS 上发生这种情况有任何帮助或建议吗?

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

这是我的 AJAX 电话

$('#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();
        }
    });           
});

这是我的控制器

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

这是我的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
    }
  }
}

注意:我在 AJAX 中尝试使用以下 URL,但出现以下错误

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

这是我的 IIS 配置文件

有几个问题可能会发生这种情况。

  1. 检查您的 IIS 服务器代码的数据库连接是否正常。
  2. 如果您从特定文件夹中检索任何文件或数据,请检查您的文件夹的权限。
  3. 检查您的 URL 是否正在 ajax 向您的控制器 post 验证它 post 控制器的有效数据和传入响应也有效。