Checking if a user exists in Active Directory using C# or VB.Net
You can use the .Net Wrapper to see if a user exists in Active Directory or not.
Programming Langauges Supported
ASP.NET, C#, VB.Net, Visual Studio 2010, Visual Sutdio 2008
Method: UserExists
Parameters: (string) Username
Precondition
An instance of the LDAP manager must be instantiated for a valid ADDS server.
Functionality
The method is called passing the Username as a string. Three
things can then occur:
- If the username exists in Active Directory and the method returns true.
- If the username does not exist in Active Directory the
method returns false
- An Exception will be thrown for other errors
Example
Where LdapConnection is an instance of LdapManager
public Boolean UserExists(String UserName)
{
try
{
return LdapConnection.UserExists(UserName);
}
catch (Exception)
{
throw;
}
}
Post Condition
It should be noted that there is no residual connection to the authenticated
User Name, this method does not result in any "Login" context.
|