简体   繁体   中英

How to connect to LDAP server in asp.net using C#

I am making an application is asp.net to check some transaction reports. I want to use bank ldap server because bank employes can only access that application and check those reports. So please guide me for the ldap connection in asp.net using c# (Windows authentication)

If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

Basically, you can define a domain context and easily find users and/or groups in AD:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// validate credentials
bool isValid = ctx.ValidateCredentials("myuser", "mypassword");

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

The new S.DS.AM makes it really easy to play around with users and groups in AD!

Additionally, in ASP.NET, you might need to make sure that either the account your web site is running under (in IIS) has the permissions to read out AD, or you might need to supply separate credentials for AD access by using one of the several overloaded constructors for PrincipalContext

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM