views:

266

answers:

2

Possible Duplicate:
How to get current user in Asp.Net MVC

I've tried a bunch of different things, I know I've done it before when I used Webforms, but I can't seem to figure out how to do it in MVC.

Membership doesn't work User gives me an IPrincipal or something User.Identity gives me the same type of variable...

Anyone know? Is there any GetCurrentUser() method or something similar?

A: 
Page.User.Identity

Page should be referencing System.Web.UI.Page

check do you have any class named "Page" within your project

Rony
A: 

See Mehrdad's answer here: http://stackoverflow.com/questions/1045593/system-web-ui-page-wont-let-me-access-currentuser-or-user-identity-from-a-contro/1045607#1045607

He explains that you can to use

User.Identity // in the controller
HttpContext.User.Identity // in the controller
System.Web.HttpContext.Current.User.Identity // anywhere
Matt

related questions