Fraz Sundal
Fraz Sundal

Reputation: 10448

Integrating Active Directory in my asp.net website

In my website i want to use active directory users for authentication. how can i do this.

Upvotes: 1

Views: 3038

Answers (2)

marc_s
marc_s

Reputation: 755321

If you need to do programmatic validation of credentials against Active Directory, you should use the new System.DirectoryServices.AccountManagement classes that are available in .NET 3.5.

Read the Managing Directory Security Principals in the .NET Framework 3.5 in the January 2008 issue of MSDN Magazine for more info. NOTE: only CHM download

For validating credentials, you'd have to create a principal context - either a machine (single server) or domain (network) and then call the .ValidateCredentials() method on it:

using System.DirectoryServices.AccountManagement;

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN");

if(ctx.ValidateCredentials(userName, password))
{
    // user is validated
}

Pretty simple, isn't it?? This works great if your users need to log in using a form where they enter username and password and you can grab these to check their account.

Upvotes: 2

Tim Coker
Tim Coker

Reputation: 6524

You need to specify Windows Authentication in your web.config

<system.web>
    <authentication mode="Windows"/>
</system.web>

Then set up allow/deny blocks to specify users who have access, etc.

<authorization>
  <allow roles="AuthorizedADGroup" />
  <allow users="AllowedUserName" />
  <deny users="*" />
  <deny users="?"/>      
</authorization>

Upvotes: 2

Related Questions