将匿名连接到.net中的ldap服务器 [英] connect anonymous to ldap server in .net
本文介绍了将匿名连接到.net中的ldap服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何通过c#.net将匿名用户连接到ldap服务器?
Hi all,
How to connect as anonymous user to ldap server through c# .net?
推荐答案
以下代码示例展示了如何搜索域中的所有用户。它包含一些基本的必需任务,例如使用C#try-catch或Visual Basic .NET try-catch-finally语句来捕获可能抛出的所有错误的错误和错误处理通过DirectorySearcher对象。
http://msdn.microsoft.com/en-us/library/ms180885(v = vs.80).aspx [ ^ ]
"The following code examples show how to search for all users in a domain. It contains some basic required tasks such as using a C# try-catch or Visual Basic .NET try-catch-finally statement to catch errors and error handling for all the errors that can be thrown by the DirectorySearcher object."
http://msdn.microsoft.com/en-us/library/ms180885(v=vs.80).aspx[^]
try
{
string username =@"your username"
string password =@"your password"
// Bind to the users container.
DirectoryEntry entry = new DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com",username,password);
// Create a DirectorySearcher object.
DirectorySearcher mySearcher = new DirectorySearcher(entry);
// Create a SearchResultCollection object to hold a collection of SearchResults
// returned by the FindAll method.
SearchResultCollection result = mySearcher.FindAll();
// Get search results. For more information, see Getting Search Results.
// ...
// This sample uses Try...Catch to catch errors.
// Create an Exception object. For more information, see System.Exception.
}
catch (System.Runtime.InteropServices.COMException)
{
System.Runtime.InteropServices.COMException exception = new System.Runtime.InteropServices.COMException();
Console.WriteLine(exception);
}
catch (InvalidOperationException)
{
InvalidOperationException InvOpEx = new InvalidOperationException();
Console.WriteLine(InvOpEx.Message);
}
catch (NotSupportedException)
{
NotSupportedException NotSuppEx = new NotSupportedException();
Console.WriteLine(NotSuppEx.Message);
}
这篇关于将匿名连接到.net中的ldap服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文