ASP.Net MVC 3 如何更新用户帐户?
我想更新我的项目中的用户帐户。我有一个这样的视图:
@using (Html.BeginForm("edit/" + @Model.SysUsers[0].UserID, "cpanel/sysuser",
FormMethod.Post))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>@Model.SysUsers[0].UserID</legend>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserName)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserEmail)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserEmail)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserEmail)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserComment)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserComment)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserComment)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserLocked)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserLocked)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserLocked)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserApproved)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserApproved)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserApproved)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserOffice)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.SysUsers[0].UserOffice, new
SelectList(Model.GetawayOffice, "OfficeCode", "OfficeDesc",
Model.SysUsers[0].UserOffice))
@Html.ValidationMessageFor(model => model.SysUsers[0].UserOffice)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
控制器是这样的:
public ActionResult Edit(string id)
{
model.SysUsers = repo.SelectSystemUser(id).ToList();
model.Office = reps.Office().ToList();
return View(model);
}
[HttpPost]
public ActionResult Edit(string id, FormCollection collection)
{
//update in System_User Table
Guid UserId = new Guid(id.ToString());
var SysUser = db.System_User.Single(s => s.User_UserId == UserId);
SysUser.User_Office = collection["SysUsers[0].UserOffice"];
//update aspnet_membership, like comment, email, isLocked, isApproved
...
}
我可以在 Sytem_User 表中更新 Office,但如何更新 aspnet_membership (用于更新评论、电子邮件、isLocked、isApproved)?
我认为我必须使用
membership.UpdateUser(MembershipUser User)
,但有人能给我一个如何使用membership.UpdateUser 的例子吗?
现在我可以更新用户评论和用户电子邮件,我使用这个:
var usermembership = Membership.GetUser(UserId);
usermembership.Comment = collection["SysUsers[0].UserComment"];
Membership.UpdateUser(usermembership);
usermembership.Email = collection["SysUsers[0].UserEmail"];
Membership.UpdateUser(usermembership);
但是,我无法更新用户锁定和用户批准。如何更新那些?
谢谢
i want to update user account in my project. i have a view like this :
@using (Html.BeginForm("edit/" + @Model.SysUsers[0].UserID, "cpanel/sysuser",
FormMethod.Post))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>@Model.SysUsers[0].UserID</legend>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserName)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserEmail)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserEmail)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserEmail)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserComment)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserComment)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserComment)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserLocked)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserLocked)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserLocked)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserApproved)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SysUsers[0].UserApproved)
@Html.ValidationMessageFor(model => model.SysUsers[0].UserApproved)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SysUsers[0].UserOffice)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.SysUsers[0].UserOffice, new
SelectList(Model.GetawayOffice, "OfficeCode", "OfficeDesc",
Model.SysUsers[0].UserOffice))
@Html.ValidationMessageFor(model => model.SysUsers[0].UserOffice)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
and the controller is like this :
public ActionResult Edit(string id)
{
model.SysUsers = repo.SelectSystemUser(id).ToList();
model.Office = reps.Office().ToList();
return View(model);
}
[HttpPost]
public ActionResult Edit(string id, FormCollection collection)
{
//update in System_User Table
Guid UserId = new Guid(id.ToString());
var SysUser = db.System_User.Single(s => s.User_UserId == UserId);
SysUser.User_Office = collection["SysUsers[0].UserOffice"];
//update aspnet_membership, like comment, email, isLocked, isApproved
...
}
i can update Office in Sytem_User table, but how can I update aspnet_membership (its for updting comment, email, isLocked, isApproved) ?
i think that i must use
membership.UpdateUser(MembershipUser User)
but can someone give me an example how to use membership.UpdateUser ?
now i can update user comment and user email, i use this :
var usermembership = Membership.GetUser(UserId);
usermembership.Comment = collection["SysUsers[0].UserComment"];
Membership.UpdateUser(usermembership);
usermembership.Email = collection["SysUsers[0].UserEmail"];
Membership.UpdateUser(usermembership);
but, i cant update user locked and user approve. how to update thoose ?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Membership.UpdateUser 方法
Membership.UpdateUser Method
查看 http://msdn。 microsoft.com/en-us/library/system.web.security.membership.updateuser.aspx
可能是 ASP.Net MVC 3 Membership.UpdateUser(MembershipUser 用户)
嗯 - 我认为你走在正确的轨道上。也许可以看看使用会员资格的应用程序的示例。
这里我使用 WebForms 来更改密码:
祝你好运。
Have a look at http://msdn.microsoft.com/en-us/library/system.web.security.membership.updateuser.aspx
Possible dupe of ASP.Net MVC 3 Membership.UpdateUser(MembershipUser user)
Hmm - I think you are on the right track. Perhaps have a look around for examples of apps that use membership.
Here I am using WebForms to change a password:
Good luck.
我认为一种方法是编写您的 onwmembershipuser 实现。
请查看这篇文章“如何:实现自定义成员资格用户”。
如果您不喜欢实现每个方法,您可以创建一个后代类并仅编写行为不同所需的方法,然后在 web.config 中声明您的新提供程序
I think a way would be the one to write your onw membershipuser implementation.
Look at this post "How to: Implement a Custom Membership User".
If you don't like to implement every method you can create a descendant class and write only the methods you need to behave differently, then declare your new provider in the web.config