IPrincipal or membership to retrieve username

What is the difference when getting a username for submission?

<%= Page.User.Identity.Name %> 

or

 <%= Membership.GetUser().UserName %> 
+4
source share
4 answers

According to the documentation , GetUser receives information from the data source and updates the date / time stamp of the last activity for the current registered user.

Page.User.Identity.Name does not do this. He reads information that is easily accessible in memory.

+4
source

Page.User.Identity.Name specify the identifier of the current user. Membership.GetUser () allows you to get information about the user.

BTW, a call to getUser () without a parameter is the same as

 Membership.GetUser(Page.User.Identity.Name) 

So, if you just need a username, use Page.User.Identity.Username and use Memberhip.GetUser () to get more information about the user, for example, about email, or to perform an action with the user, for example, change the password.

Hope this helps

+3
source

Page.User.Identity is populated when the page passes through the pipeline.

Membership.GetUser (). UserName is sent and received again from the database, Active Directory, or anywhere the provider is supported, which causes a second search.

This is unlikely to change, so I would use page.User.Identity.

+2
source

Note that it is entirely possible to have a User.Identity.Name link to a user who does not even exist in the membership database. This is Form Authentication and a general abstraction of the User concept, which does not necessarily exist even in the membership database.

If you delete the current user from the membership database, then User.Identity.Name retain its original value.

0
source

Source: https://habr.com/ru/post/1299032/


All Articles