Optimizing Performance on Sitecore Sites with Millions of Users (Continued)
I wrote a previous post here that talked about how to ensure good performance when you have a Sitecore site that allows for users that sign in to the site. Even before I wrote that post I knew of an issue that I resolved, which I did not mention in the post. The issue is w/ the JSS Dictionary Service and some other services JSS uses that requires running as sitecore\ServicesAPI user. The issue is that I suggest disabling the membership provider and Sitecore does a check against the membership provider to verify the user exists. I figured after all this time I would share a workaround for this issue in case anyone hits it. The simple solution is, just replace the DisabledMembershipProvider.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | namespace BissTalk.Project.Site.Security { using System; using System.Collections.Generic; using System.Globalization; using System.Web.Security; using Sitecore.Security; /// <summary> /// overrides the default <see cref="DisabledMembersipProvider" /> to support returning anonymous user. /// </summary> /// <seealso cref="Sitecore.Security.DisabledMembersipProvider" /> public class DisabledMembershipProviderForJss : DisabledMembersipProvider { /// <summary> /// The list of all anonymous users. /// </summary> private static readonly Dictionary<string, MembershipUser> _users = new Dictionary<string, MembershipUser> { {"extranet\\anonymous", CreateUser("extranet\\Anonymous")}, {"default\\anonymous", CreateUser("default\\Anonymous")}, {"sitecore\\servicesapi", CreateUser("sitecore\\ServicesAPI")} }; /// <summary> /// Gets the user if it is an anonymous user's name, otherwise executes base GetUser. /// </summary> /// <param name="username">Name of the user.</param> /// <param name="userIsOnline">If the user is currently online.</param> /// <returns>The user, if it is an anonymous user's name, otherwise executes base GetUser.</returns> public override MembershipUser GetUser(string username, bool userIsOnline) { var name = username.ToLower(CultureInfo.InvariantCulture); return _users.ContainsKey(name) ? _users[name] : base.GetUser(username, userIsOnline); } /// <summary> /// Creates a user. /// </summary> /// <param name="userName">Name of the user.</param> /// <returns>A user with the given user name.</returns> private static MembershipUser CreateUser(string userName) { return new MembershipUser("disabled", userName, userName, null, null, null, true, false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue); } } } |
And then in your web.config...
1 2 3 4 5 6 7 8 9 | <membership defaultProvider="switcher" hashAlgorithmType="SHA1"> <providers> <clear /> <add name="sitecore" type="Sitecore.Security.SitecoreMembershipProvider, Sitecore.Kernel" realProviderName="sql" providerWildcard="%" raiseEvents="true" /> <add name="sql" type="System.Web.Security.SqlMembershipProvider" connectionStringName="security" applicationName="sitecore" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" /> <add name="disabled" type="BissTalk.Project.Site.Security.DisabledMembershipProvider, BissTalk.Project.Site" applicationName="sitecore" /> <add name="switcher" type="Sitecore.Security.SwitchingMembershipProvider, Sitecore.Kernel" applicationName="sitecore" mappings="switchingProviders/membership" /> </providers> </membership> |
Problem Solved!!
P.S. This is example code. In real life you may want to put the list of users in a patch config rather than hard-coding them.
No comments :
Post a Comment