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?
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?
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.