Relate, MVC, Windows Authentication and email address becomes empty

Vote:
 

Hello,

I have a Relate based MVC site using Windows Authentication. When a new user accesses the site a user record is added to the Community database as expected but the email address is empty. Now this is ok as we have a scheduled job that imports further user detail to the record including email address.

Periodically though, seemingly every day, the email address is blanked out ie empty string. Does anyone know what causes this or how it may be fixed?

Thanks,

Mark

#91315
Oct 02, 2014 10:25
Vote:
 

Hard question to answer. We need more information. How does the code that fetches the email address look like.

Be aware that there are email addresses stored in many places. You find one on the membership user object, another on the EPiServer profile wrapper and finally a property on Relates User object.

#91417
Oct 03, 2014 23:27
Vote:
 

Hi Fredrik,

Well we're using the standard Relate provider but we have added some addtional fields and customised the edit user screen (but based on the screen provided). The code that fetches the user is EPiServer.Common.Settings.DefaultSecurity.GetUser passing in an integer ID.

I can see that when the email is empty that the IUser object has an empty string email and when I set and save the email this value is populated. Later the email will be empty again.

I wonder if it's something to to do with the authentication method resetting the email to an empty string when authenticating. As I mentioned we are using Windows authentication so I wonder if this picks up an empty string and overwrites the value saved. If this is the case I don't know how to test for this.

Thanks,

Mark

#91609
Edited, Oct 09, 2014 12:58
Vote:
 

Hi Mark,

 

I had exactly the same problem and in order to fix you need to save e-mail in two places, here is code fragment. It self-descriptive and with comments just let me know if something not clear

// Save user using Relate API
SecurityHandler.Instance.UpdateUser(entity);

            // Code bellow keeps synchronized community user email and cms user e-mail. 
            // Otherwise when windows authorization is enabled there is side effect and community user e-mail is replaced with cms user e-mail on login 
            var entityEpiProfile = EPiServer.Personalization.EPiServerProfile.Get(entity.UserName);

            // do not perform update if community user e-mail and cms user e-mail are already the same
            if (entityEpiProfile.Email != entity.EMail)
            {
                entityEpiProfile.Email = entity.EMail;
                entityEpiProfile.Save();
            }
#91626
Oct 09, 2014 16:41
Vote:
 

Yes, all users will have an ASP.NET Profile object in EPiServer and it implements storage of an email address and there is also a method to get that email address with fallback to the membership users email (which may be empty in an AD membership provider scenario).

I have a vauge memory that Relate syncronize the email address with the login so that is probably what happens.

Sergey's code should solve the problem!

#91643
Oct 09, 2014 17:31
Vote:
 

Hi Sergey and Fredrik,

Thanks for the code snippet I have added it in but it doesn't seem to solve the issue. I can step through the code and see that the email address of the CMS user (EPiServerProfile) is set to the email I set in the Relate profile. However, after refreshing the site I can see that the Relate email is empty again and stepping through the code sjows me that the CMS email still has the value.

Am I missing something obvious here?

Thanks,

Mark

#91662
Oct 10, 2014 11:50
Vote:
 

Hi Mark,

Please try to save e-mail from CMS->Admin mode and check if e-mail for the same user but in Relate->Admin mode is synchronized after re-login. In my case it did. Also what do u have in membership configuration?

#91663
Oct 10, 2014 12:14
Vote:
 

Hi Sergey,

I can see that the email address is set in CMS > Admin and although it states that you can't edit fields due to the provider it does allow you to save. Viewing the account in Community > Admin mode still shows the email address as blank so saving in CMS does not populate the Community user.

The configuration we have for this is:

      <roleManager enabled="true" defaultProvider="EPiServerCommonRoleProvider" cacheRolesInCookie="true">
        <providers>
          <clear />
          <add name="EPiServerCommonRoleProvider" applicationName="ClientSite" type="EPiServer.Common.Web.Authorization.RoleProvider, EPiServer.Common.Web.Authorization" />
        </providers>
      </roleManager>
      <membership defaultProvider="MultiplexingMembershipProvider" userIsOnlineTimeWindow="10">
        <providers>
          <clear />
          <add name="MultiplexingMembershipProvider" type="EPiServer.Common.Web.Authorization.Multiplexing.IntegrationMultiplexingMembershipProvider, EPiServer.Common.Web.Authorization.Multiplexing" provider1="EPiServerCommonIntegrationMembershipProvider" provider2="EPiServerCommonMembershipProvider" provider3="WindowsMembershipProvider" roleToSynchronize1="*" />
          <add name="EPiServerCommonIntegrationMembershipProvider" applicationName="ClientSite" type="EPiServer.Common.Web.Authorization.IntegrationMembershipProvider, EPiServer.Common.Web.Authorization" provider="WindowsMembershipProvider" />
          <add name="EPiServerCommonMembershipProvider" applicationName="ClientSite" type="EPiServer.Common.Web.Authorization.MembershipProvider, EPiServer.Common.Web.Authorization" />
          <add name="WindowsMembershipProvider" type="EPiServer.Security.WindowsMembershipProvider,EPiServer" deletePrefix="BUILTIN\" searchByEmail="true" />
        </providers>
      </membership>

#109703
Oct 13, 2014 13:13
Vote:
 

Hi Mark,

In my case it also states that I can't edit filed but on my side e-mail is still available for editing (and this e-mail overwrites community e-mail each login). Also I have slightly different configuration. You can apply the same and see if it works for you. Otherwise I don't have more recommendations from my side.

<membership defaultProvider="EPiServerCommonIntegrationMembershipProvider" userIsOnlineTimeWindow="10">
  <providers>
    <clear />    
    <add name="EPiServerCommonIntegrationMembershipProvider" applicationName="EPiServerRelate" type="EPiServer.Common.Web.Authorization.IntegrationMembershipProvider, EPiServer.Common.Web.Authorization" provider="WindowsMembershipProvider" roleToSynchronize1="*"/>

    <add name="WindowsMembershipProvider" applicationName="EPiServerRelate" type="EPiServer.Security.WindowsMembershipProvider, EPiServer" deletePrefix="BUILTIN\" searchByEmail="true" />    
    
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="MultiplexingRoleProvider" cacheRolesInCookie="true">
  <providers>
    <clear />
    <add name="MultiplexingRoleProvider" applicationName="EPiServerRelate" type="EPiServer.Security.MultiplexingRoleProvider, EPiServer" 
         provider1="EPiServerCommonRoleProvider" provider2="WindowsRoleProvider" 
         providerMap1="EPiServerCommonMembershipProvider" providerMap2="WindowsMembershipProvider" />    
    <add name="WindowsRoleProvider" applicationName="EPiServerRelate" type="EPiServer.Security.WindowsRoleProvider, EPiServer" />
    <add name="EPiServerCommonRoleProvider" applicationName="EPiServerRelate" type="EPiServer.Common.Web.Authorization.RoleProvider, EPiServer.Common.Web.Authorization" />        
  </providers>
</roleManager>



#109723
Oct 13, 2014 16:39
Vote:
 

Hi Sergey,

I tried using your configuration above and along with your code snippet this seems to work and the email address has stayed constant for nearly two days.

Strangely though I'm not getting any results for edit user in CMS mode. I'm not too concerned about this as you're not supposed to be able to use this provider anyway. I'm just conscious of any other side affects that might crop up (none yet!).

Thanks ever so much for your help with his.

Mark

#109831
Oct 15, 2014 16:11
Vote:
 

Hi Mark,

I need to double check for how long it's constant in my case I though forever but now I am not sure. I havn't notice about other side effects either.

#109833
Oct 15, 2014 16:26
Vote:
 

Hi Sergey,

Bad news, the email address is empty again...

#111618
Oct 16, 2014 15:28
Vote:
 

Hi Mark,

Double checked on my side and e-mail is ok (last edit was several weeks ago) along with other profile properties. So not sure what's wrong on yuor side.

#111619
Oct 16, 2014 15:35
Vote:
 

Thanks for the update, I've just raised a support ticket for this.

Thanks,

Mark

#111621
Oct 16, 2014 15:38
Vote:
 

Hi Mark,

Did you ever find a solution to this issue? Did EPiServer provide a solution for you? I'm experiencing the same problem. I see that Sergeys posts are marked green but from the last post it looks like they didn't work for you?

Regards

Markus Thorén

#131749
Aug 04, 2015 17:55
Vote:
 

Hi Markus,

Yes we did resolve this and as I recall we had to override the default WindowsMembershipProvider and remove the if statement from the code below.

if (EPiServerProfile.Enabled)
{
     email = EPiServerProfile.Get(username).Email;
}

We also had to update the WindowsMembershipProvider assembly in the web.config to point to the overriden code.

I hope this helps,

Mark

#131783
Aug 05, 2015 11:01
Vote:
 

Ok, thanks for the update, I'll try that.

BR

Markus

#131800
Aug 05, 2015 14:55
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.