ASP.NET MVC Forms Authentication with Active Directory
This is a very basic example of how to integrate Active Directory Authentication using ASP.NET MVC. This is very easy and requires only about 10 minutes to accomplish.
ASP.NET MVC Templates already have the required code and configuration to use the Authentication, so all we need to do is change the configuration to point to our Active Directory instead of SQL Express.
To do this you will need an accessible Active Directory and Visual Studio with MVC templates installed. I won’t show you how to install and configure AD here as I do not have this knowledge, yet!
- Create a new ASP.NET MVC Web Application

- Visual Studio will ask you if you want to create a test project, I usually work in TDD so I always say yes. You should now have 2 projects in your solution.

- If you open the Web.Config file and locate the <connectionStrings>, you will notice there is already a connection; you can remove it and add a new one for you Active Directory.

- Now locate the tags authentication, membership, profile, roleManager and remove them (or comment out). Insert these

- Now run the solution and try it using an existing user. You will need to use username@domain for the authentication to work.
This entry was posted on Monday, May 4th, 2009 at 9:15 am and is filed under ASP.NET, Active Directory, C#.NET, Developement, MVC. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Mike June 2nd, 2009 at 5:15 pm
Hello Sergio, I’m currently building an application that requires ActiveDirectory authentication and role management from AD groups. Correct me if i’m wrong, but there is no out of the box solution for this.
I haven’t had time to look into it very much so far, but I plan on doing something similar to the [Authorize(Roles="admin"]attribute so that I could change my data source from AD to SQL Server easily.
I’ll blog about it once I’ve done something!