What is Active Directory
A directory service from Microsoft that is a part of Windows 2000. It is an implementation of Internet standard directory and naming protocols that uses a database engine for transactional support, and also supports a variety of application programming interface standards.System.DirectoryServices Namespace
The System.DirectoryServices namespace provides easy access to Active Directory Domain Services from managed code. The namespace contains two component classes, DirectoryEntry and DirectorySearcher, which use the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a flexible tool for working with a variety of network providers. ADSI gives the administrator the ability to locate and manage resources on a network with relative ease, regardless of the size of the network.System.DirectoryServices.ActiveDirectory Namespace
The System.DirectoryServices.ActiveDirectory namespace provides a high level abstraction object model that builds around Microsoft Active Directory services tasks. The Active Directory service concepts such as forest, domain, site, subnet, partition, and schema are part of the object model. The System.DirectoryServices.ActiveDirectory namespace is used to automate Active Directory management tasks. System.DirectoryServices.ActiveDirectory is not used to access data that resides within Active Directory or any other directory service. The System.DirectoryServices namespace should be used for this purpose. The System.DirectoryServices.ActiveDirectory namespace is intended for use by application developers who are familiar with .NET Framework programming using Visual Basic .NET or C#. Knowledge of directory services programming is also helpful. System.DirectoryServices.ActiveDirectory is part of Microsoft Visual Studio 2005 and is supported on any operating system that Microsoft Visual Studio 2005 is compatible with. Many of the classes, methods, and properties in the System.DirectoryServices.ActiveDirectory namespace use the LinkDemand code access security option. This means that the code access security demand only occurs during just-in- time compilation and that the demand is performed only on the calling assembly and not up the entire call stack. Because of this, callers should not pass objects created from this namespace at runtime to untrusted code.Use ActiveDirectory to check credential
private void checkActiveDirectoryLogin(string strUsername, string strPassword) { bool isAuthenticated = false; System.DirectoryServices.DirectoryEntry Entry = new System.DirectoryServices.DirectoryEntry(); System.DirectoryServices.DirectorySearcher Searcher = new System.DirectoryServices.DirectorySearcher(); System.DirectoryServices.SearchResult Results = default(System.DirectoryServices.SearchResult); string domainName = null; try { Entry.Path = "LDAP://" + domainName;// SERVER/USERGROUP Entry.Username = strUsername; Entry.Password = strPassword; Searcher.SearchRoot = Entry; Searcher.SearchScope = System.DirectoryServices.SearchScope.OneLevel; Results = Searcher.FindOne(); isAuthenticated = (Results != null); if (isAuthenticated) { //Code for Successful Login } else { // Code for unsuccessful login } } catch (Exception ex) { throw ex; } }
Comments
Post a Comment