我正在尝试在 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);