繁体   English   中英

IIS 10 AJAX 不适用于 do.net 核心 5 MVC

[英]IIS 10 AJAX not working for dotnet core 5 MVC

我正在编写一个 asp dot.net 核心 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();
        }
    });           
});

这是我的 controller

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. 检查您通过 ajax 向 controller 发布的 URL 的验证,它会将有效数据发布到 controller,并且传入响应也有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM