Asp – Retrieving session information with ASP.NET MVC

asp.net

Let's say you have an ASP.NET MVC web application with a page that is accessible to all registered users of your application. Now this page has mostly general information, but there is also one panel that shows the current logged in user's personal information. How do you go about implementing this?

My initial thought would be to have the controller read the current logged in user's ID from the session and pull the information necessary and pass that into the view. But that seems somewhat awkward to me for some reason to pull session information from within the controller. Is this the only way to do it?

Best Solution

With MVC preview 5 you get authorization controller. It sets user name or id in cookie when user logins, and you can read it with User.Identity.Name (if i remember correct) Now, in one component (or ex user control in previous versions) you can read that id or username, or get data from session or db, and display rest of user info.