1

我使用下面的代码来验证 LDAP 中的用户和密码:

        bool authentic = false;

        string ip_server = "10.53.41.21";
        string userName = "CN=test,N=Users,DC=user,DC=domain,DC=COM";
        string password = "something";
        try
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://" + ip_server, userName, password);
            //   entry.
            object nativeObject = entry.NativeObject;
            authentic = true;
        }
        catch (DirectoryServicesCOMException) { }
        return authentic;

它在本地和 IIS 6.0 上运行良好。但是在 IIS 7.0 上运行时会出错:

System.DirectoryServices.DirectoryServicesCOMException (0x8007203B): A local error has occurred.

   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_NativeObject()

如何解决这个问题?

谢谢!

4

1 回答 1

1

您正在传递distinguishedName用户名的属性,它应该采用以下格式:domain\username

于 2013-01-21T16:08:59.280 回答