Bug #29

MembershipProvider.UpdateUser

Added by Rodney Lai 11 months ago. Updated 6 months ago.

Status:Assigned Start:09/15/2009
Priority:Normal Due date:
Assigned to:Daniel Nauck % Done:

20%

Category:Membership Spent time: 2.00 hours
Target version:2.0 Estimated time:1.00 hour

Description

MembershipProvider.UpdateUser doesn't look at RequiresUniqueEmail when saving new e-mail address

History

Updated by Daniel Nauck 11 months ago

  • Category set to Membership
  • Assigned to set to Daniel Nauck
  • Target version set to 2.0

Updated by Daniel Nauck 6 months ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 10

As far as i know the original SqlMembershipProvider also does not check for unique e-mail addresses in the UpdateUser method.

Should we implement this as optional feature?

Updated by Daniel Nauck 6 months ago

  • Due date set to 01/28/2010
  • Status changed from Feedback to Rejected
  • % Done changed from 10 to 100

The default membership behavior is not to check for unique emails while updating a user.

If i implement a custom exception that is thrown when updating a user it maybe that the caller of UpdateUser() is not aware of this exception.

So if you want to validate unique email addresses try the following code:

1 var user = myMembershipUserObject;
2 
3 if (!string.IsNullOrEmpty(Membership.GetUserNameByEmail(user.Email)))
4     throw new Exception("Duplicate email address...");
5 
6 Membersip.IpdateUser(user);

Updated by Rodney Lai 6 months ago

yeah, the default behavior is not to check for unique email address, but
there is an option RequiresUniqueEmail in MembershipProvider
and if this property is set to true UpdateUser throws an exception
if the email address is not unique

Updated by Daniel Nauck 6 months ago

  • Due date deleted (01/28/2010)
  • Status changed from Rejected to Assigned
  • % Done changed from 100 to 20
  • Estimated time set to 1.00

Hello,

you're right.

I get the following exception when calling Membership.UpdateUser() when the e-mail address already exists:

English:

System.Configuration.Provider.ProviderException was unhandled by user code
  Message="The E-mail supplied is invalid." 
  Source="System.Web" 
  StackTrace:
       at System.Web.Security.SqlMembershipProvider.UpdateUser(MembershipUser user)
       at System.Web.Security.MembershipUser.Update()
       at System.Web.Security.Membership.UpdateUser(MembershipUser user)
  InnerException: 

German:

System.Configuration.Provider.ProviderException was unhandled by user code
  Message="Die angegebene E-Mail-Adresse ist ungültig." 
  Source="System.Web" 
  StackTrace:
       bei System.Web.Security.SqlMembershipProvider.UpdateUser(MembershipUser user)
       bei System.Web.Security.MembershipUser.Update()
       bei System.Web.Security.Membership.UpdateUser(MembershipUser user)
  InnerException:

So, ticket is reopend. I'll fix this asap.

Thanks.

Also available in: Atom PDF