Most of the things I read about using AD with ASP.NET ends up being way more complex than it needs to be. Toss this in your web.config between the system.web tags:
<
authentication mode="Windows" />
<identity impersonate="true"/>
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
<providers>
<clear/>
<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
<membership defaultProvider="ADMembershipProvider">
<providers>
<add name="ADMembershipProvider" applicationName="/" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" connectionProtection="Secure" />
</providers>
</membership>
Make sure your virtual or site is using Integrated Windows Authentication.
Done. Not a believer?
Well, I kind of lied. If you are on XP, you really cant get this to work without hard coding a username and password for a domain user who has access to query LDAP into the membership provider (I guess that is how Microsoft defines secure by default, patch please) so change that guy to look like this:
<
add name="ADMembershipProvider" applicationName="/" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" connectionUsername="Domain\user" connectionPassword="securepassword" connectionProtection="Secure" />
Run your code, pop into a break point and type
Membership.GetUser() which will return a Membership user with a bunch of info about you, and try Roles.GetRolesForUser() will will get all of your roles or Roles.IsUserInRole("role") which will return true if you are in a role, false if you aren't or FileNotFound otherwise. (Just Kidding). You can add/remove roles etc.
BLAM! Winner! Between the membership and roles providers you can pretty much do anything you can do from the AD Users and Groups snap-in, all from the comforts of C#.
Brought to you by the letters 'A' and 'D'