Saturday, April 18, 2015

ASP.NET Forms Authentication with Active Directory using .NET 4.0/4.5

If you read this MSDN article on Forms Authentication with Active Directory, you will notice that still only addresses ASP.NET 2.0:  https://msdn.microsoft.com/en-us/library/ff650308.aspx

The Web.config element in fact still refers to .NET 2.0 assemblies.  Therefore, if you are using a newer version of the .NET Framework such as .NET v. 4.0 or .NET v. 4.5, then you may be wondering what the newer Web.config entry should be.

Well, it is remarkably similar to the original entry with just a change to the version information:

<membership defaultProvider="MyADMembershipProvider">

      <providers>

        <add

           name="MyADMembershipProvider"

           type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

           connectionStringName="ADConnectionString"

           connectionUsername="testdomain\administrator"

           connectionPassword="password"/>

      </providers>

</membership>

Alternatively, you can just use the following element:


<membership defaultProvider="ADMembershipProvider">

      <providers>

        <clear />

        <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" connectionUsername="testdomain\administrator" connectionPassword="password" />

      </providers>

</membership>


That’s all you have to change!!


No comments:

Post a Comment