如何使用javascript验证Active Directory中的用户(将用户名和密码传递给LDAP用户身份验证)?

时间:2016-09-28 06:26:28

标签: javascript active-directory ldap ldap-query active-directory-group

我创建了一个Web服务并进行了Ajax调用,以验证用户是否可以访问Active Directory。当我们通过Intranet访问时它正在工作,但是当通过Web访问该站点时我收到错误。这是我的代码片段:

jQuery.support.cors = true;

    $("#dialog-form").dialog({
        autoOpen: false,
        height: 330,
        width: 380,
        cache: false,
        modal: true,
        buttons: {
            "Authenticate": function () {
                var bValid = true;
                allFields.removeClass("ui-state-error");
                bValid = bValid && checkLength(name, "Username", 1, 30);

                if (!LoginUserCheck(name.val()) && bValid) {
                    updateTips("The Username entered here should match with Username used for logging into the system");
                }

                bValid = bValid && checkLength(password, "Password", 1, 30);
                bValid = bValid && LoginUserCheck(name.val());

                if (bValid) {
                    var dataString = "{'username':'" + name.val() + "' ,password: '" + password.val() + "'}";
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "http://192.168.12.186:5327/LDAPService.asmx/LADPAuthenticationCheck",
                        data: dataString,
                        dataType: "json",
                        beforeSend: function (xhr) { xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); },
                        success: function (msg) {
                            if (msg.d) {
                                $("#dialog-form").dialog("close");
                                $("#dialog").dialog("open");
                                // alert("MSG :" + msg.d);
                            }
                            else {
                                updateTips("Incorrect Username/Password");
                            }
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            //                            $("#dialog").dialog("open");
                            alert("Error: " + errorThrown + " Please try to login with some other's system.");
                        }
                    });
                }
            },
            Cancel: function () {
                $("#dialog-form").dialog("close");
                $('#<%= hdnCancel.ClientID %>').trigger("click");
            }
        },
        close: function () {
            allFields.val("").removeClass("ui-state-error");
        }
    });

    $('#<%= hdnTriggerDialog.ClientID %>').click(function () {
        $("#dialog-form").dialog("open");
    });
});

我怀疑当通过网络访问网站时跨域失败。有人可以帮我解决一下吗?

谢谢 - 拉古

0 个答案:

没有答案