2
votes

I want to build a user registration store for Sitecore 8 website. The users will go in an external database.

  • Sitecore.NET 8.0 (rev. 150223)
  • .NET Framework 4.0.30319.18052
  • Razor Version=3.0.0.0
  • MVC 5.2.3.0

Asp.net MVC comes with the membership built in (AccountController, views, etc). I wanted to port this to my Sitecore project. The problem is Sitecore also uses membership internally. I know there is a way for getting membership working for the Sitecore 6.x versions through the switching providers described at Sitecore authenticate users against external membership database.

Is it still the same process for Sitecore 8?

3

3 Answers

2
votes

This still applies to Sitecore 8 and the core asp.net membership features and the switching membership provider can still be used. The mongo db side of Sitecore 8 is for xDb, but you still use membership systems to authenticate.

I won't provide any further detail as the post you referenced seems to cover it all. Just in case there's another good post here:

https://himadritechblog.wordpress.com/2014/11/24/sitecore-custom-membership-provider/

Make sure you declare a new domain for you membership system in your domains.config.

1
votes

I ended up not using the SimpleMembership and just going with Membership. I could not get the adapter that the thecodeking link mentions to work.

This method is not properly documented. I just had to change the config files. I did not have to create a custom class that inherits from MembershipProvider.

Web.config:

In membership section,

  • change realProviderName to "switcher"
  • copy "sql" node and change name and connectionStringName to "external"

In switchingProviders section,

  • add "external" node with domains "external"

web.config:

<membership defaultProvider="sitecore" hashAlgorithmType="SHA1">
  <providers>
    <clear />
    <!-- change realProviderName to "switcher" -->
    <add name="sitecore"
         type="Sitecore.Security.SitecoreMembershipProvider, Sitecore.Kernel"
         realProviderName="switcher"
         providerWildcard="%"
         raiseEvents="true"
         />
    <add name="sql"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="core"
         applicationName="sitecore"
         minRequiredPasswordLength="1"
         minRequiredNonalphanumericCharacters="0"
         requiresQuestionAndAnswer="false"
         requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="256"
         />
    <add name="switcher"
         type="Sitecore.Security.SwitchingMembershipProvider, Sitecore.Kernel"
         applicationName="sitecore"
         mappings="switchingProviders/membership"
         />
    <!-- copy "sql" node and change name and connectionStringName to "external" -->
    <add name="external"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="external"
         applicationName="sitecore"
         minRequiredPasswordLength="1"
         minRequiredNonalphanumericCharacters="0"
         requiresQuestionAndAnswer="false"
         requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="256"
         />
  </providers>
</membership>

<switchingProviders>
  <membership>
    <provider providerName="sql" storeFullNames="true" wildcard="%" domains="*" />
    <!-- add "external" node with domains "external" -->
    <provider providerName="external" storeFullNames="true" wildcard="%" domains="external" />
  </membership>
</switchingProviders>

ConnectionStrings.config:

  • add connection "external"

config:

<add name="external" connectionString="..." providerName="System.Data.SqlClient"/>

Domains.config:

  • add domain "external"

config:

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

Then use the "external" provider directly which saves user to external db. This is the key point.

// uses "external" provider directly
Membership.Providers["external"].CreateUser(...)

Instead of this which saves to core db.

// uses default provider
Membership.CreateUser(...)
0
votes

I personally like to keep the membership logic very simple and away from custom providers. Sitecore has a concept of Virtual User that you can instantiate once you authenticate on the external DB. You can set any custom properties on this virtual user and let sitecore record it in xDB. Here is a good example.