0

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?

Community
  • 1
  • 1
Matt
  • 5,249
  • 12
  • 40
  • 45
  • 3
    duplicate of http://stackoverflow.com/questions/263486/how-to-get-current-user-in-asp-net-mvc – Jacob Mattison Jun 25 '09 at 17:33
  • wow that's hilarious, I always check the list of recommended questions after I type in the title and the title is almost the exact same... my apologies – Matt Jun 25 '09 at 17:42
  • Just tried Page.User.Identity as well as Page.CurrentUser. Both of them give me an error saying System.Web.UI.Page does not contain a definition for "CurrentUser" or "User.Identity" in the case of the first one – Matt Jun 25 '09 at 17:49
  • check do you have any class named "Page" within your project – Rony Jun 25 '09 at 17:51
  • No I don't. The error says it's referencing System.Web.UI.Page – Matt Jun 25 '09 at 17:57
  • I'm trying to access it from within a Control, does that matter? – Matt Jun 25 '09 at 18:00

2 Answers2

10

See Mehrdad's answer here: System.Web.UI.Page won't let me access CurrentUser or User.Identity from a Controller in ASP.Net-MVC

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
Community
  • 1
  • 1
Matt
  • 5,249
  • 12
  • 40
  • 45
0
Page.User.Identity

Page should be referencing System.Web.UI.Page

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

Rony
  • 9,331
  • 2
  • 22
  • 22