External ASPNET Membership Database & Sitecore

This blog explains how to integrate external aspnet membership database (EAMDb) with Sitecore.

If your sitecore implementation requires,

  • Integration with external aspnet membership database.
  • You do not want to import / merge your users and roles from EAMDb into core database.

Then this blog will help you achieving it. Inspiration to write this blog was from one of the post in sitecore forums . Thanks for Vik Jairath for raising such a post.

Configuration

I have divided the implementation into following steps,

  • Adding Domain in domains.config
  • Adding a Connectionstring
  • Adding domain-provider mappings in web.config
  • Configuring the providers in web.config

Adding Domain in domains.config

Add and entry into app_config\security\Domains.config file for e.g. as follows,

<domain name=”extaspnet” ensureAnonymousUser=”false” />   

Adding a connectionstring

In order to connect sitecore to the EAMDb specify a connection string into app_config\ ConnectionStrings.config. It should be something like,

<add name=”dbaspnetmembership” connectionString=”user id=****;password=****;Data Source=****;Database=****”/>

Adding Domain-Provider mappings in web.config

In web.config file browse to <sitecore >/<switchingProviders>/ element.

This section contains two groups for the three membership providers i.e. <membership> and <roleManager>. Add following line to <membership> group

<provider providerName=”memproextaspnetdb” storeFullNames=”false” wildcard=”%” domains=”extaspnet” />

Add following line to <role> group

<provider providerName=”memproextaspnetdb” storeFullNames=”false” wildcard=”*” domains=”extaspnet” />

Note: If you want your AD Roles and Users to appear before sitecore roles and users the definition should precede the sql provider mapping. Hence the order of the mapping decides in which order roles and users will be seen in the Role Manager and User Manager in Sitecore.

Domains attribute value should match with value of name attribute that was specified in domains.config file.

Your <switchingProviders> section might look like

switching providers

Configuring the Providers

Configuring membership provider

Open web.config file and browse to <system.web>/<membership>, create a new entry as follows,

<add name=”memproextaspnetdb” type=”System.Web.Security.SqlMembershipProvider” connectionStringName=”dbaspnetmembership” applicationName=”sitecoredbaspnet”  requiresQuestionAndAnswer=”false” requiresUniqueEmail=”false”  minRequiredPasswordLength=”1″ minRequiredNonalphanumericCharacters=”0″ />

Configuring the Role Provider

Open web.config file and browse to <system.web>/<roleManager>, create a new entry as follows,

<add name=”memproextaspnetdb” type=”System.Web.Security.SqlRoleProvider”  connectionStringName=”dbaspnetmembership” applicationName=”sitecoredbaspnet”  />

Note: The applicationName attribute plays a vital role in such implementation and it should match to the value specified in the “aspnet_Applications” table of your external aspnet membership database.

Hence if in your aspnet_Applications table you do not have entry for applicationName, users and roles will not be visible or accessible in sitecore

Now you should be able to see all the users and roles in sitecore User Manager and Role manager respectively from your external database.

ASPNet Membership - Application table

Sitecore can be configured with Active directory, Custom Provider as well as default sitecore membership provider all in a single go.

More documentation and blogs

You can further quench your technical thirst for membership providers and sitecore integration with following resources.

Leave a Reply

Your email address will not be published. Required fields are marked *