Saving an email change within the default Membership Provider in ASP.NET MVC

前端 未结 2 1733
别跟我提以往
别跟我提以往 2020-12-19 03:16

I am trying to set and save an email change using within the Membership Provider in ASP.NET MVC 3. I do not know how to properly set and change the email property within th

相关标签:
2条回答
  • 2020-12-19 03:32

    Try UpdateUser:

    var user = Membership.GetUser(id);
    user.Email = "new@email.com";
    Membership.UpdateUser(user);
    
    0 讨论(0)
  • 2020-12-19 03:36

    I'd like to emphasise a point, following on from @Ecnalyr and @jwaern. When changing the email address, assigning the email address directly as follows did not work:

    System.Web.Security.Membership.GetUser.email = newEmail '(this won't work)
    

    First, as shown in the responses above, one must assign the MembershipUser to a variable, and only then affect an UpdateUser on that variable.

    Dim mu As MembershipUser = System.Web.Security.Membership.GetUser
    mu.Email = email
    Membership.UpdateUser(mu)
    
    0 讨论(0)
提交回复
热议问题