Using Multiple ASP SQL Role providers on multiple SharePoint Sites.

I found this problem as I was extending a SharePoint site to use FBA and the client wanted the users of Site 2 in a different database  than that of  Site 1.

Here are some concepts first

You have multiple FBA profile providers , Membership Provider , and Role Provider.

You need to have the following per site


  • Site1MembershipProvider
  • Site1RoleProvider
  • Site1ProfileProvider


  • Site1MembershipProvider
  • Site1RoleProvider
  • Site1ProfileProvider


All in one web.Config file / application

While that is obviously not doable without custom provider , yet , you will still have the challenge of dynamically switching the provider at runtime.

Here is the fix no coding needed.

ProfileCommon class only points to the properties under the  Default provider

Yet, you can trick it with the following.

<profile enabled=”true” defaultProvider=”SQLProfile”>

<!–  The “name” attribute of each property entry corresponds, that is the ProfileCommon properties–>


<add name=”FirstName” />

<add name=”MiddleName” />

<add name=”LastName” />

<!– Required Sharepoint properties follow… –>

<add name=”PreferredName” defaultValue=”NA” />

<add name=”WorkEmail” defaultValue=”” />

<add name=”WorkPhone” type=”System.String” defaultValue=”NA” />

<!– Required for the Custom Profile Site1 –>

<add name=”Site1FirstName”  type=”string” provider =”FBASite1Profile”/>

<add name=”Site1MiddleName” type=”string” provider =”FBASite1Profile”/>

<add name=”Site1LastName”   type=”string” provider =”FBASite1Profile”/>



<add name=”SQLProfile” type=”System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”AspNetSqlProvider” applicationName=”/” />

<add name=”FBASite1Profile” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”FBASite1ConnectionString” applicationName=”Site1Application” />


<add name=”FBASite2Profile” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”FBASite2ConnectionString” applicationName=”Site2Application” />


<add name=”FBASite3Profile” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”FBASite3ConnectionString” applicationName=”Site3Application” />



Accessing the profile through code

Creating a profile

MembershipUser  newUser = Membership.Providers[“Site1Membership”].CreateUser(UsernameTextbox.Text, PasswordTextbox.Text,EmailTextbox.Text, passwordQuestion,passwordAnswer, chkActive.Checked,(object)Guid.NewGuid(), out status);

ProfileCommon pc = (ProfileCommon)ProfileBase.Create(newUser.UserName);

pc.SetPropertyValue(“Site1FirstName”, FirstName.Text);

pc.SetPropertyValue(“Site1MiddleName”, MiddleName.Text);

pc.SetPropertyValue(“Site1LastName”, LastName.Text);


Reading a profile

MembershipUser user = Membership.Providers[“Site1Membership”].GetUser(username,false);

ProfileCommon pc = (ProfileCommon)ProfileBase.Create(user.UserName);

FirstName.Text = pc.GetPropertyValue(“Site1FirstName”).ToString() ;

MiddleName.Text= pc.GetPropertyValue(“Site1MiddleName”).ToString();

LastName.Text = pc.GetPropertyValue(“Site1LastName”).ToString();

Good Luck .


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s