开发者

does Page.User make a call do the database

I was using Membership.getUser() to get t开发者_JAVA百科he currently logged in user but I recently discovered that each time this it called, the data is retrieved from the database.

If page.user also makes a call to the db then how can I get the currently logged on user without continuously hitting the db.

It would be difficult to store and manage this object in session.


Page.User will not hit the DB.

You can get the name of the currently logged in user from HttpContext without hitting the DB.

string userName = HttpContext.Current.User.Identity.Name;

OR

string userName = Page.User.Identity.Name;


you can use HttpContext.User.Identity [MSDN]

if (User.Identity.IsAuthenticated)
{
    Page.Title = "Home page for " + User.Identity.Name;
}
else
{
    Page.Title = "Home page for guest user.";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜