Reputation: 34203
I know you can do this to get the User Id for the current user
(Guid)Membership.GetUser().ProviderUserKey;
But this does a DB lookup. Is there any way to get the GUID of the current user without a DB lookup, can it be determined from the auth cookie?
Upvotes: 1
Views: 89
Reputation: 3265
Unfortunately, no. The Membership.GetUser() call uses the "username" for this lookup.
The auth cookie contains only this username (and a few other details, e.g. issue and expiry date)
If this is something you really need, you may be able to lookup once, and store it in the UserData property in the cookie - Change the user data in FormsAuthenticationTicket programmatically
Upvotes: 1