Hi friends, I'm developing a system to manage the users of a domain. Functions to create and update are already been createds, but is missing a function to verify if a user exists in Active Directory. I have tried to use the code typed below:
public static bool UserExists(string user) {
bool exist = false;
if (DirectoryEntry.Exists("WinNT://casa.local/10.1.1.37/" + user)) exist = true;
return exist; }
When the user exists, the function DirectoryEntry.Exists returns true and the method continue to end. But, if the user not exists, the function DirectoryEntry.Exists not returns false, but throw a Exception "Generic error". I already tried to use the DirectorySearcher
objects, but return error that the server not support search.
I need a solution to my problem, a method to verify if a user exist.
Bressan
0 Points
6 Posts
Active Directory: Verify if a user exists (???)
Feb 17, 2009 06:04 PM|LINK
Hi friends, I'm developing a system to manage the users of a domain. Functions to create and update are already been createds, but is missing a function to verify if a user exists in Active Directory. I have tried to use the code typed below:
public static bool UserExists(string user) {
bool exist = false;
if (DirectoryEntry.Exists("WinNT://casa.local/10.1.1.37/" + user)) exist = true;
return exist; }
When the user exists, the function DirectoryEntry.Exists returns true and the method continue to end. But, if the user not exists, the function DirectoryEntry.Exists not returns false, but throw a Exception "Generic error". I already tried to use the DirectorySearcher objects, but return error that the server not support search.
I need a solution to my problem, a method to verify if a user exist.
If you can help me, I"ll be happy =)
Thank You!
Active Directory user AD
Kumar Reddi
Star
14340 Points
2619 Posts
Re: Active Directory: Verify if a user exists (???)
Feb 17, 2009 07:25 PM|LINK
Try the code in this blog post.
http://www.willasrari.com/blog/query-active-directory-users-using-c/000133.aspx
krou
Member
2 Points
1 Post
Re: Active Directory: Verify if a user exists (???)
Mar 16, 2011 12:28 AM|LINK
you may want to check out the verify if user exists in active directory function