1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Telerik.Security.UserManager.Default.UpdateUser

Telerik.Security.UserManager.Default.UpdateUser

4 posts, 0 answered
  1. Eric
    Eric avatar
    23 posts
    Registered:
    01 Aug 2007
    11 Jul 2008
    Link to this post
    I noticed that when I use this method to update a user, and put in an email address that already exists in the users table, the email address is updated, even though I have requiresUniqueEmail="true" in the web .config. Is this a bug?
  2. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    11 Jul 2008
    Link to this post
    Hello Eric,

    It seems this is the default behavior of the System.Web.Security.SqlMembershipProvider.UpdateUser method and this is not a bug.
    You can change the functionality if you like by simply overriding the membership provider. Here is the custom class you need to use:

    using System; 
    using Telerik.DataAccess.AspnetProviders; 
    using System.Web.Security; 
    using System.Configuration.Provider; 
     
    public class CustomMembership : TelerikMembershipProvider 
        public override void UpdateUser(MembershipUser user) 
        { 
            int count; 
            MembershipUserCollection users = this.FindUsersByEmail(user.Email, 0, 3, out count); 
     
            // there is at least one user with this email 
            // and it is not the user we are updating 
            if (count > 0 && !users[user.UserName].Email.Equals(user.Email)) 
                throw (new ProviderException("Such email already exists")); 
            else if (count > 1) 
                throw (new ProviderException("Such email already exists")); 
            else 
                base.UpdateUser(user); 
        } 

    I hope this helps.
    Please let me know if more assistance is needed.

    All the best,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Eric
    Eric avatar
    23 posts
    Registered:
    01 Aug 2007
    11 Jul 2008
    Link to this post
    Hi Yasen, the code you sent was throwing an error. The following statement works correctly:

    if (count > 0 && users[user.UserName] == null)

    Thanks for your help. It works correctly now.
  4. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    15 Jul 2008
    Link to this post
    Hello Eric,

    Sorry, I haven't tested it thoroughly, it was more like a hint how you could solve the issue. What I meant was:

    Find users with this email.
    if([there is such user] &&
        [the user we found is not the one we are upgrading]

    This would mean that when we find at least one user with the email of the user we are updating, we should first check if it is not the same user. If it's not, an then exception is thrown. Also, it is wrong to have more than one such users.

    Best wishes,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered