views:

98

answers:

2

MVC 2, so I do not know if it is different. I am trying to add a page so that when a user is logged in, they click on their username at the upper right of the page, and it takes them to a page showing their details (email, change password link, profile information, etc..). I am trying to use the aspnet MembershipService to do this.

A: 

It will be the same as in 1.0, and as asked here: http://stackoverflow.com/questions/263486/how-to-get-current-user-in-asp-net-mvc

MikeB
Far from the same question. The one you linked to is 'how to get the current user'. I want to generate a controller action and view that displays the details about the user.
esac
you'll have to give more detail about what you are looking to do then, because once you have the object, the rest is just your app. If you have some code that isn't working or something, that might help.
BioBuckyBall
Agree with yetapb. Which bit are you struggling with? Creating a View? Controller? Model? Using the Membership provider?
MikeB
A: 

In your controller action do something like :

string id = HttpContext.User.Identity.Name.ToString();

ProfileBase profileBase;
if (!String.IsNullOrEmpty(id))
       profileBase = ProfileBase.Create(id);
else
       profileBase = HttpContext.Profile as ProfileBase;

With the profileBase object you can get all the profile attributes:

profileBase.GetPropertyValue("PersonalInformation.FirstName")

With these properties you can fill a custom view model object, for example:

public class ProfileInformation
{
   public string FirstName { get; set; }
}

and pass it to the view:

return View(profileInformation);

In the view declare you''ll receive a ProfileInformation object like this :

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
    Inherits="System.Web.Mvc.ViewPage<AzureBright.Models.ProfileInformation>" %>

And then generate the Editor fields like this:

<%= Html.EditorFor(profile => profile)%>

Hope this is what you wanted to know

Carlos Fernandes