Ajax 调用返回错误 401 未经授权

Ajax call returning error 401 Unauthorized

我正在使用 HTML 和 JavaScript (jQuery) 开发 Web 应用程序,用于数据库通信 我在 C# 中使用 .asmx Web 服务。

在本地计算机和本地 IIS 上部署我的应用程序工作正常。问题是现在我需要在公司 Web 服务器上部署我的应用程序,现在每个 ajax 调用都不起作用并且 returns 错误 401。奇怪的是,如果我进入 ajax 调用 url(显示 asmx 网络服务)然后 return 到我的网站并重新加载页面,现在所有 ajax 通话有效。例如:

$.ajax({
   url: "http://192.168.46.87/MyApp/ws_WebService.asmx/Login"

这个ajax调用returns错误401,之后如果我进入urlhttp://192.168.46.87/MyApp/ws_WebService.asmx我的网站服务已加载,如果我现在重新加载网页的选项卡,ajax 调用工作正常。

这是我的 ajax 电话:

function CallWM(webMethod, JSONToSend, callBackFunction, extraData) {
    try {
        $.ajax({
            type: 'POST',
            url: "http://192.168.46.87/MyApp/" + webMethod,
            contentType: 'application/json',
            dataType: 'json',
            data: JSON.stringify(JSONToSend),
            success: function (data, strErr, xhr) {
                callBackFunction(data.d, extraData);
            },
            error: function (xhr, textStatus, errorThrown) {
                bootbox.alert("Error calling the server!\n" + xhr.statusText);                                
                console.log(xhr.statusText);
                console.log(xhr);
                $.unblockUI();
            }
        });
    }
    catch (err) {
       bootbox.alert("Error calling the server!\n" + err.message);
       $.unblockUI();
    }
}

我已经尝试更改服务器 IIS 上的身份验证类型,通过 ajax 调用发送我的凭据,但我收到相同的错误消息,我还可以尝试什么其他方法或者可能是什么问题?

PD。在我的本地 IIS 上运行完美,现在的问题是我正在将我的应用程序移动到 Web 服务器。

我终于可以解决这个问题,这里是解决方案 就我而言

在我的应用程序路径上,我有一个 Web.config,其中我没有任何与身份验证相关的内容,但我发现在 IIS inetpub 应用程序文件夹根目录上还有另一个 Web.config,在那个文件上我看到了有一些关于身份验证的东西,删除它解决了我的问题。