。net Web应用程序在VS中运行,但在IIS中获取404,生成错误的URL

问题描述 投票:0回答:1

我有一个名为Facility的.net 4.6.2 MVC应用程序,该应用程序在Visual Studio中运行良好,但在IIS中失败。准备好文档后,浏览器将运行以下功能:

function getInspectionEvents() {
    $.get("/Inspection/GetInspectionEvents", function (data) {
        model.inspection.removeAll();
        for (var i = 0; i < data.length; i++) {
            model.inspection.push(data[i]);
        }
    });
}

在f12中>网络,我看到一堆404错误。它抱怨的所有请求都忽略了应用程序的名称Facility。例如:

应该是:https://(server)/Facility/Inspection/GetInspectionEvents

是:https://(server)/Inspection/GetInspectionEvents

我该如何解决?

我尝试将获取更改为:

$.get("/Facility/Inspection/GetInspectionEvents")

但是那没用。

javascript jquery asp.net-mvc
1个回答
0
投票

由于相同的来源策略,如果您当前位于http,则无法向https页面发出AJAX请求。

如果未发出跨域请求,则可以尝试以下操作:

$.ajax({
    type: "GET", 
    url: "https://(server)/Facility/Inspection/GetInspectionEvents",
    success: function(data){
        // --- your code here
             }
});

否则,请在目标域上实现CORS (cross-origin resource sharing)以允许此特定请求。

主机,端口和方案(协议)必须相同,才能使AJAX请求正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.