London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Is there any possibility to delete automatically CustomerContact if MemberShip User is deleted in the Cms?

Vote:
 

Hi!

Is there any possibility to delete automatically CustomerContact if MemberShip User is deleted in the Cms via Admin interface?

Is there possibility to subscribe to the MemberShip User delete?

#119819
Apr 03, 2015 11:09
Vote:
 

Hi Sviatlana,

DefaultMembershipProvider doesn't have deleted user event, but you can create your own membership provider.
I'll use AlloyTech as a sample project, and extend SqlServerMembershipProvider:

1. Inside Business folder, create CustomMembershipProvider:

using System.Web.Providers;

namespace AlloyTech.Business
{
    public class CustomMembershipProvider : DefaultMembershipProvider
    {
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            // TODO: cleanup code
            return base.DeleteUser(username, deleteAllRelatedData);
        }
    }
}

2. In web.config, register a new membership provider and set it as default one:

<membership defaultProvider="CustomMembershipProvider" userIsOnlineTimeWindow="10" hashAlgorithmType="HMACSHA512">
  <providers>
    <clear />
    <add name="CustomMembershipProvider" type="AlloyTech.Business.CustomMembershipProvider, AlloyTech"
          connectionStringName="EPiServerDB" enablePasswordRetrieval="false" enablePasswordReset="true"
          requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
          maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
          passwordAttemptWindow="10" applicationName="/"/>
		  
    ...
  </providers>
</membership>

3. In admin mode, if you get an exception when you try to create / delete user, just restart the IIS (or kill IIS Express Worker process from task manager)

That's it. Hope it helps :)

#119827
Apr 04, 2015 0:00
Vote:
 

Thank you very much!

#119873
Apr 06, 2015 7:59
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.