我试图在ASP.NET MVC 3的Membership Provider中设置和保存电子邮件更改。我不知道如何在Membership Provider中正确设置和更改email属性。

MSDN似乎建议使用MembershipUser.Email属性,因为它“获取或设置成员(member)用户的电子邮件地址”,但是我不知道如何使它正常运行。

我正在尝试使用以下代码:

// 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 = "[email protected]";
Membership.UpdateUser(user);

关于asp.net-mvc - 将电子邮件更改保存在ASP.NET MVC的默认成员资格提供程序中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10245017/

10-09 14:25