Session or Request

Should I store the user ID, name and email address in the session variable, or should I request the user ID, name and email address every time I need to use it?

+4
source share
3 answers
public class UserInfo { public int UserID {get;set;} public string Email {get;set;} ... } 

When the user logs in, create an instance of UserInfo and save it in the session.

+1
source

Store it in a session variable. It’s better to cache your frequently used data in the application instead of having a bunch of round trips to the server.

+1
source

If you use ASP.NET security, that is, membership providers and role providers, etc., you do not need to store them. Membership Provider:

  MembershipUser myObject = Membership.GetUser(); string UserID = myObject.ProviderUserKey.ToString(); 

In addition, if you authenticate the user on each page, which occurs automatically on the secure website, then the membership provider should not return to the database to receive data, since it is already available for the current request.

If you use a ready-made profile provider, I would advise you to use and download the table-based provider mentioned in Scott Gug’s blog: http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx This much friendlier and much better than the default provider.

+1
source

Source: https://habr.com/ru/post/1310448/


All Articles