1

MVC 2,所以我不知道它是否不同。我正在尝试添加一个页面,以便当用户登录时,他们单击页面右上角的用户名,然后将他们带到显示其详细信息(电子邮件、更改密码链接、个人资料信息等)的页面..)。我正在尝试使用 aspnet MembershipService 来执行此操作。

4

2 回答 2

0

它将与 1.0 中的相同,并在此处询问:如何在 ASP.NET MVC 中获取当前用户

于 2009-11-19T16:17:50.000 回答
0

在您的控制器操作中执行以下操作:

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)%>

Hope this is what you wanted to know

于 2009-11-20T13:44:30.733 回答