LDAP连接仅在本地主机上工作

本文关键字:主机 工作 连接 LDAP | 更新日期: 2023-09-27 17:53:16

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

我需要找出为什么它只适用于一个而不适用于另一个。如有任何意见,不胜感激。

            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);

LDAP连接仅在本地主机上工作

我发现它在创建用户主体时抛出了错误。因此,我将其更改为获取组主体并使用重载进行包含,这样我就可以从表单中传入用户名。

            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);
相关文章: