Using ASP.NET membership, if I want to get information for the current user, I can call MembershipUser.GetUser()
So, somehow the system must know the ID of the current user.
If this is correct, and all I want is the ID of the current user, is there a way to get it without returning all the user information from the database?
I know I can get the username of the current user using User.Identity.Name, but I need the ID.
After looking into this further, it seems that the ASP.NET Membership API does not track the user ID after all. It must track just the user name (
User.Identity.Name). The ID is not required becauseMembership.GetUser()can find a user from an ID or user name.In fact,
Membership.GetUser()must simply translate toMembership.GetUser(User.Identity.Name). Since it can obtain the current user from the user name, there is no longer any reason to assume that the current user ID is cached anywhere.So it appears the ID is not loaded into memory, and the only way to obtain the ID is to load the data from the database (which means loading the entire user record when using the ASP.NET Membership API).