Return to
HomePage, ASPNET2SecurityFAQs
Question: How do I use Forms Authentication with Active Directory?
Answer:
Use the built-in
ActiveDirectoryMembershipProvider. Use the new login controls to create a forms authentication login page.
To use forms authentication with an Active Directory user store:
* Configure your application for Forms Authentication in the Web.Config file as follows
<authentication mode="Forms">
* Configure your application to deny access to unauthenticated users in the Web.config file as follows:
<authorization>
<deny users="?"/>
</authorization>
* Configure an LDAP connection string in the connectionStrings section of Web.config to point to the Active Directory to be used.
<connectionStrings>
<add name="ADConnectionString"
connectionString="LDAP://testdomain.test.com/CN=Users,
DC=testdomain,DC=test,DC=com" />
</connectionStrings>
* Configure the
ActiveDirectoryMembershipProvider in the Web.config file specifying at least the connection string name and optionally the credentials (using
connectionUserName and connectionPassword attributes) of an account with permissions to access Active Directory. If you do not specify account credentials, your application's process identity is used to access Active Directory, regardless of whether your application uses impersonation.
* Ensure that the
defaultProvider attribute is set to the provider configured.
<membership defaultProvider="MyADMembershipProvider">
<providers>
<add
name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="testdomain\administrator"
connectionPassword="password"/>
</providers>
</membership>
* Use the Login control to create a login page (login.aspx) for forms authentication.
* Encrypt the connectionStrings section using protected configuration. Also if you specify user credentials in the
ActiveDirectoryMembershipProvider configuration encrypt the membership configuration section as well.
More Information
For information on forms authentication using Active Directory, see “How To: Use Forms Authentication with Active Directory in ASP.NET 2.0” at http://msdn.microsoft.com/library/en-us/dnpag2/html/PAGHT000026.asp
Return to
HomePage, ASPNET2SecurityFAQs