简体   繁体   中英

Getting invalid email error when I try to update a user?

I am trying to update the Comments for a user but when I try using the code below:

MembershipUser User = Membership.GetUser(UserName);
User.Comment = "Whatever...";
Membership.UpdateUser(User);

It throws the error:

The E-mail supplied is invalid.

I've checked the email right before I call UpdateUser and it's fine. Can anyone see why this would be happening?

UPDATE:

Stack trace -

[ProviderException: The E-mail supplied is invalid.]
   System.Web.Security.SqlMembershipProvider.UpdateUser(MembershipUser user) +1583
   System.Web.Security.MembershipUser.Update() +111
   Security_Login.btnSubmit_Click(Object sender, EventArgs e) in c:\inetpub\V1\VerbalInk.Web\Security\Login.aspx.cs:40
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

There is possibly Duplicate Email Address in database. if you set requiresUniqueEmail to false in Membership Connection String , set it to true .

<add name="AspNetSqlMembershipProvider" applicationName="blah" 
connectionStringName="balh" enablePasswordReset="true" enablePasswordRetrieval="false"
maxInvalidPasswordAttempts="5" minRequiredNonalphanumericCharacters="0" 
minRequiredPasswordLength="5" passwordAttemptWindow="15" passwordFormat="Hashed"    
requiresQuestionAndAnswer="false" **requiresUniqueEmail="true"** 
type="System.Web.Security.SqlMembershipProvider" />

This turned out to have been caused by there being another record in my aspnet_Membership table that had the same email address as the record I was trying to update. This is a testing database so I'm guessing I must have added it manually or something a while back, because with the current system it isn't possible to create duplicates.

For some reason they have a pretty misleading error message that suggests there is something wrong with the email address when, in fact, the issue is related to duplicate emails.

Hope this can help someone in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM