Should I store user data in a session or use a custom profile provider?

On my site, when a user logs in, I create a session object with the following properties

DisplayName, Email, MemberId 

Questions

  • Would it be wiser to use a custom profile provider to store user data?
  • What is the pro and con of each approach (session provider and custom profiles)?
  • Does it make sense to use a custom provider to read only data that can come from one or more tables?
+1
source share
1 answer

My answer is not a direct approach to your question. This is just an alternative approach.

Instead of a custom profile provider, I create my own context to track the currently registered user profile. Here is a sample code. You can store DisplayName, Email, MemberId instead of the MyUser class.

 void Application_AuthenticateRequest(object sender, EventArgs e) { if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated) { MyContext.Current.MyUser = YOURCODE.GetUserByUsername(HttpContext.Current.User.Identity.Name); } } public class MyContext { private MyUser _myUser; public static MyContext Current { get { if (HttpContext.Current.Items["MyContext"] == null) { MyContext context = new MyContext(); HttpContext.Current.Items.Add("MyContext", context); return context; } return (MyContext) HttpContext.Current.Items["MyContext"]; } } public MyUser MyUser { get { return _myUser; } set { _myUser = value; } } } } 
+2
source

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


All Articles