LDAP 连接仅适用于本地主机

LDAP connection only works on localhost

我有一个登录页面,它使用活动目录验证凭据并重定向到下一页。当我 运行 它在本地运行完美时,但是当我把它放在我们的网络服务器上时,它在尝试创建组主体时出错:(System.DirectoryServices.DirectoryServicesCOMException (0x80072020))

我需要找出为什么它适用于一个而不适用于另一个。非常感谢任何输入。

            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain.com");
            GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Building Webmasters");
            UserPrincipal up = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, txtUserName.Value);

            bool auth = ctx.ValidateCredentials(txtUserName.Value, txtPassword.Value);
            bool groupauth = grp.Members.Contains(up);

我发现它在创建用户主体时抛出了错误。因此,我将其更改为获取组主体并执行一个包含重载的操作,我可以只从表单中传入用户名。这对我有用。

            bool auth = ctx.ValidateCredentials(txtUserName.Value, txtPassword.Value);
            bool groupauth = grp.Members.Contains(ctx, IdentityType.SamAccountName, txtUserName.Value);
            bool adminauth = admingrp.Members.Contains(ctx, IdentityType.SamAccountName, txtUserName.Value);