tags:

views:

93

answers:

1

If I'm coding in a View in Asp.net MVC and I want to get the current user, is it better to use

Page.User

or

HttpContext.User

Is there a difference?

+5  A: 

Page.User returns this.Context.User which is exactly the same as HttpContext.User, so it makes no difference, both point to the same object in memory. As a side note, I would recommend you not to use either of these in a View Page, let the controller pass the needed data to the view in which case you have a third choise which is the Controller.User property.

Darin Dimitrov
Why is it not recommended to use Page.User or HttpContext.User and to pass the user info through the controller?
mawaldne
Because in an MVC model the role of a View is to show data that is being passed by the controller. It is not a view's responsibility to pull data.
Darin Dimitrov