【发布时间】:2009-11-20 21:44:30
【问题描述】:
MVC 2,所以我不知道它是否不同。我正在尝试添加一个页面,以便当用户登录时,他们单击页面右上角的用户名,然后将他们带到显示其详细信息(电子邮件、更改密码链接、个人资料信息等)的页面..)。我正在尝试使用 aspnet MembershipService 来执行此操作。
【问题讨论】:
MVC 2,所以我不知道它是否不同。我正在尝试添加一个页面,以便当用户登录时,他们单击页面右上角的用户名,然后将他们带到显示其详细信息(电子邮件、更改密码链接、个人资料信息等)的页面..)。我正在尝试使用 aspnet MembershipService 来执行此操作。
【问题讨论】:
在您的控制器操作中执行以下操作:
string id = HttpContext.User.Identity.Name.ToString();
ProfileBase profileBase;
if (!String.IsNullOrEmpty(id))
profileBase = ProfileBase.Create(id);
else
profileBase = HttpContext.Profile as ProfileBase;
使用 profileBase 对象,您可以获得所有配置文件属性:
profileBase.GetPropertyValue("PersonalInformation.FirstName")
使用这些属性,您可以填充自定义视图模型对象,例如:
public class ProfileInformation
{
public string FirstName { get; set; }
}
并将其传递给视图:
return View(profileInformation);
在视图声明中,您将收到一个 ProfileInformation 对象,如下所示:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<AzureBright.Models.ProfileInformation>" %>
然后像这样生成编辑器字段:
<%= Html.EditorFor(profile => profile)%>
希望这是你想知道的
【讨论】:
这将与 1.0 中的相同,并在此处询问:How to get the current user in ASP.NET MVC
【讨论】: