开发者

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.


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).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜