2
votes

I am looking to create a product catalogue site using Sitecore that will allow users to save products into custom lists they can manage when they use the website.

These lists could potentially contain hundreds of items each so using the standard custom profile attributes could get out of hand so I thought using an external data source would be the best way.

Are there any examples of how to implement a custom profile provider that stores to an external sql database? Is there a better way to do this?

UPDATE To expand on this. To test, I have downloaded the SQL Table Profile Provider example from here: http://code.msdn.microsoft.com/Using-the-SQL-Table-4c220996 and have that running using. I have then added a reference to this provider in the Sitecore project. In the web.config I have:

<profile defaultProvider="switcher" enabled="true" inherits="Sitecore.Security.UserProfile" >
        <providers>
            <clear />

           <add name="sql" type="System.Web.Profile.SqlProfileProvider"  connectionStringName="core" applicationName="sitecore" />

           <add name="TableProfileProvider"
                   type="Microsoft.Samples.SqlTableProfileProvider, SQLTableProfileProviderCS"
                   connectionStringName="myProfileConnString" table="aspnet_Profile2"
                   applicationName="/" />

            <add name="switcher" type="Sitecore.Security.SwitchingProfileProvider, Sitecore.Kernel" applicationName="sitecore" mappings="switchingProviders/profile" />
        </providers>
        <properties>
            <clear />
            <add type="System.String" name="SC_UserData" />

        </properties>
    </profile>

and under switchingProviders:

        <profile>
            <provider providerName="TableProfileProvider" storeFullNames="false" wildcard="%" domains="mydomain" />
            <provider providerName="sql" storeFullNames="true" wildcard="%" domains="*" />
        </profile>

and in /Security/Domains.config:

<domain name="mydomain" ensureAnonymousUser="false"/>

If I try to obtain the current users' profile and access the custom attributes using the same method as the SQL Table Profile Provider example project, the custom profile is always null.

I must be missing something in my configuration. Any suggestions would be greatly appreciated.

2
Do you mean a membership provider?Mark Ursino
My understanding was that there is membership, roles and profile providers. I'm fine using the standard sitecore membership provider, I just want to extend the profile information to store custom attributes outside of the default asp.net attributes as i've heard storing too much information in there can cause performance issues. Do I need to use a custom membership provider to make the profile provider work?Bevan

2 Answers

4
votes

You will find this document interesting. It contains the low-level details on how provider system works as well as gives special recommendations on implementing the custom providers in context of Sitecore.

UPDATE: I don't think you should implement other types of providers if you just want to extend the profile functionality with some properties from external storage. These pieces are quite independent, however I didn't try it myself.

Generally, what you're looking for is referenced as "partial profile feature" in Sitecore docs. And the document I mentioned above contains the following note:

Important The option to have different sets of user profile properties in different storages is not supported by the default Sitecore CMS installation. You must install the Active Directory module and configure it accordingly in order to use this option (see the Active Directory module documentation).

So, probably some functionality to make it work hides somewhere in AD module, not in the default Sitecore CMS. I don't think you should configure the AD module - it would be pointless otherwise - just install it.

Apart from this Profile provider still stays a bit specific - take a thorough look at the section 4.2 Profile Provider Implementation Recommendations.

Finally, I would encourage you to study the topic deeper - it's quite advanced and might need some tweaking, but your scenario doesn't seem impossible to implement with what is already there.

2
votes

If I understand you correctly, I believe you can customize this in the web.config here:

<profile defaultProvider="sql" enabled="true" inherits="Sitecore.Security.UserProfile, Sitecore.Kernel">
  <providers>
    <clear />
    <add name="sql" type="System.Web.Profile.SqlProfileProvider" connectionStringName="core" applicationName="sitecore" />
    <add name="switcher" type="Sitecore.Security.SwitchingProfileProvider, Sitecore.Kernel" applicationName="sitecore" mappings="switchingProviders/profile" />
  </providers>
  ...

As you can see, the provider is a standard ASP.NET Profile Provider (reference here) -- specifically a SQL provider -- so you should be able to follow any .NET guides on how to do it.