1

I have an application which users Windows authentication in conjuction with ASPnet roles, so roles stored in a database but users on the windows domain.

I want to have a management page where admins add existing users to roles, does anyone know of a simple way I can check that the username input is valid in the active directory domain?

2 Answers 2

4

You could use the PrincipalContext class:

public bool UserExistsInAd(string username)
{
    using (var pc = new PrincipalContext(ContextType.Domain))
    {
        var up = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username);
        return up != null;
    }
}

Obviously the account you have configured your ASP.NET MVC 3 application to run under in IIS must have sufficient privileges to access the Active Drectory.

Sign up to request clarification or add additional context in comments.

Comments

0

Lookup System.DirectoryServices namespace

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.