保存在ASP.NET MVC的默认成员资格提供内变更电邮(Saving an email chang

2019-06-23 19:38发布

我想设置和保存使用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);

Answer 1:

尝试UpdateUser两个:

var user = Membership.GetUser(id);
user.Email = "new@email.com";
Membership.UpdateUser(user);


文章来源: Saving an email change within the default Membership Provider in ASP.NET MVC