What is the difference when retrieving username for the view?
<%= Page.User.Identity.Name %>
or
<%= Membership.GetUser().UserName %>
What is the difference when retrieving username for the view?
<%= Page.User.Identity.Name %>
or
<%= Membership.GetUser().UserName %>
According to the documentation, GetUser
gets the information from the data source and updates the last-activity date/time stamp for the current logged-on membership user.
Page.User.Identity.Name
does not do that. It reads information that is readily available in memory.
Page.User.Identity gets populated when the page goes through the pipeline.
Membership.GetUser().UserName goes and gets the information again, from the database, Active Directory or wherever else the provider supports, causing a second lookup.
It's unlikely to change, so I'd use Page.User.Identity.
Page.User.Identity.Name give the identity of the currently logged user. Membership.GetUser() allow you to get the information about the user.
BTW, calling getUser() without parameter is the same as
Membership.GetUser(Page.User.Identity.Name)
So, if you just need the userName, use Page.User.Identity.Username and use Membership.GetUser() to get more informations about the user, like the email, or to perform action on the user like changing his password.
Hope it will help