2

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.

Bevan
  • 281
  • 6
  • 17
  • Do you mean a membership provider? – Mark Ursino Feb 21 '12 at 02:14
  • 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 Feb 21 '12 at 03:03

2 Answers2

4

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.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • thanks, i've worked through this document and the result is broken membership – Bevan Feb 21 '12 at 06:43
  • "broken membership" is quite a vast description... it would be great if you enrich your question with greater detail of how it is broken – Yan Sklyarenko Feb 21 '12 at 06:45
  • Sorry. I went through the document but found that the implementation of the profile provider not as detailed as the membership or role providers. When I activated the sitecore provider switcher, the sitecore installation just froze up when trying to do anything relating to members. I'm obviously doing something wrong... Do I need to implement a membership provider to get the profile provider to work? – Bevan Feb 21 '12 at 11:02
  • Thanks Yan, I hadn't thought to look at the AD Module as active directory wasn't to be used. I'll take a look at that module and see if it can help me find out how to get my implementation working. – Bevan Feb 21 '12 at 22:44
  • I've gone through the AD Module &the Low Level Sitecore Cms Security and Custom Providers doc & haven't got any further. I can get my custom profile provider working fine in an application outside Sitecore but when trying to integrate it into Sitecore it is just not using the custom provider. I suspect it is related to activating the profile provider switcher but I've tried the setup/configuration steps outlined in those previous documents but the switcher doesn't appear to be using my provider. Do you know of any other documentation regarding integration of a profile provider into Sitecore? – Bevan Feb 24 '12 at 03:49
2

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.

Mark Ursino
  • 31,209
  • 11
  • 51
  • 83
  • I have tried going through the .net guides and have got it working in an example outside of sitecore but when I try to integrate that into sitecore and use the profile provider switcher (as I thought was required) it breaks the existing sitecore userprofiles and results in being unable to login to sitecore. I'm looking for more information on the integration with sitecore itself. – Bevan Feb 21 '12 at 03:52
  • Try using the documentation specified by Yan ;-). – Younes Feb 21 '12 at 07:23