我正在ASP.NET MVC 3中的成员资格提供程序中设置并保存电子邮件更改.我不知道如何正确设置和更改成员资格提供程序中的电子邮件属性.
MSDN似乎建议MembershipUser.Email属性,“获取或设置成员用户的电子邮件地址”,但我不知道如何使其正常运行.
我试图使用这个代码:
// change email MembershipUser u = Membership.GetUser(User.Identity.Name); u.Email = email; // Is this working as expected? u.Save(); // this line doesn't do anything - what should it be? db.Save(); <-- that is what I would do with ordinary database changes,but I don't know what context to use for Membership Provider changes. . .
编辑:
我想到了:
// change email MembershipUser u = Membership.GetUser(User.Identity.Name); u.Email = email; System.Web.Security.Membership.UpdateUser(u);
解决方法
尝试UpdateUser:
var user = Membership.GetUser(id); user.Email = "new@email.com"; Membership.UpdateUser(user);