Jonathan Allen
Jonathan Allen

Reputation: 70307

ASP.NET: How do I get the current user without call Membership.GetUser()?

How do I get the current user without call Membership.GetUser()? I don't want to call this method because it makes a round-trip to the database.

I tried Page.User, but this doesn't return a MembershipUser object.

Upvotes: 0

Views: 281

Answers (3)

Jim
Jim

Reputation: 1735

If you just need the user's username, then just call User.Identity.Name. If you need other information about the MembershipUser, then you'll can't avoid that trip to database (unless as CResults pointed out, store the object in session).

Upvotes: 3

Saurabh
Saurabh

Reputation: 5727

when user is logged in. you can User.Identity.Name . you can check with if(User.Identity.IsAuthenticated) and User.Identity.Name. This might help you.

Upvotes: 1

CResults
CResults

Reputation: 5105

Have you considered storing it in an encrypted state in your session object?

Call GetUser once, store the result in the session and from then on get the value from the session object.

Upvotes: 1

Related Questions