[英]Why does C# DirectoryServices not work with my LDAP server?
I have a AD/LDAP server running in production that is working fine. 我有一个在生产中运行正常的AD / LDAP服务器。 I need to test things, so I created my own locally using phpldapadmin. 我需要测试,所以我使用phpldapadmin在本地创建了自己的东西。
When I attempt to do a wildcard search on objectClass
, my code throws. 当我尝试对objectClass
进行通配符搜索时,我的代码抛出了。 This only happens on my local server. 这仅在我的本地服务器上发生。
System.DirectoryServices.DirectoryServicesCOMException: 'An invalid dn syntax has been specified. System.DirectoryServices.DirectoryServicesCOMException:'指定了无效的dn语法。
I've tried multiple username syntaxes that DirectoryServices
supports: they all work on the production server and fail on my local server. 我尝试了DirectoryServices
支持的多种用户名语法:它们都在生产服务器上运行,而在我的本地服务器上失败。 I can successfully get inside and navigate my local server using JXplorer. 我可以使用JXplorer成功进入并浏览本地服务器。
class Program
{
static void Run(string ip, string username, string password)
{
var authType = System.DirectoryServices.AuthenticationTypes.None;
var directoryEntry = new DirectoryEntry(ip, username, password, authType);
var directorySearcher = new DirectorySearcher(directoryEntry, "(objectClass=*)");
directorySearcher.SearchScope = SearchScope.OneLevel;
// throws here
var searchResult = directorySearcher.FindOne();
}
static void Main(string[] args)
{
Run("LDAP://validlocalip", "admin@test", "test");
Console.ReadKey();
}
}
It doesn't like what you've passed as the path
parameter to the DirectoryEntry
constructor: 它不喜欢您作为path
参数传递给DirectoryEntry
构造函数的内容:
var directoryEntry = new DirectoryEntry(ip, username, password, authType);
That parameter is an LDAP path, not just an IP. 该参数是LDAP路径,而不仅仅是IP。 If all you have is an IP, then you can try "LDAP://ip" but usually you'd use your domain name: "LDAP://domain.com" 如果您只有IP,则可以尝试使用“ LDAP:// ip”,但通常会使用域名:“ LDAP://domain.com”
More info here: https://docs.microsoft.com/en-ca/dotnet/api/system.directoryservices.directoryentry.path 此处的更多信息: https : //docs.microsoft.com/zh-cn/dotnet/api/system.directoryservices.directoryentry.path
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.