Skip to content

CtcApi.Web.Security

Shawn (work acct) edited this page Jun 8, 2013 · 2 revisions

ActiveDirectoryRoleProvider

The .NET Framework has well-established mechanisms for providing authentication and a wide variety of authorization providers - but, strangely, it does not come with a Role provider for Active Directory. The ActiveDirectoryRoleProvider is based on the code example provided in this StackOverflow post.

To use the ActiveDirectoryRoleProvider, simply include the class in your project (by referencing the CtcApi, for example) and then add the following settings to the App.config or Web.config (inside the <system.web /> node):

 <roleManager enabled="true" defaultProvider="ActiveDirectory">
   <providers>
     <clear />
     <add name="ActiveDirectory"
          type="CtcApi.Web.Security.ActiveDirectoryRoleProvider"
          domain="YOURDOMAIN"
          groupMode=""
          connectionString="LDAP://YOUR_SERVER_LDAP_STRING" />
   </providers>
 </roleManager>

Now your code can use the standard authorization classes (such as AuthorizeFromConfigAttribute) and .NET will use the ActiveDirectoryRoleProvider to validate role membership.