November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
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.
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
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();
}
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!
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
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?
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>
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>
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
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.
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.
Thanks for the update, I've just raised a support ticket for this.
Thanks,
Mark
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
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
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