Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:17:30+00:00 2026-06-13T09:17:30+00:00

I have always stored data for a user (after they logged in) in a

  • 0

I have always stored data for a user (after they logged in) in a Session variable, so I can use that data on any page.
I found out that another way to store information globally is to store it in a class, using { get; set;}, and then calling that from any page.

Right now, I’ve used both these methods as a test, and they both work really well:

Session["LoginId"] = rdr["uniqueIdentifier"].ToString();

And

Member.LoginId = rdr["uniqueIdentifier"].ToString();

Where (In Member.cs)

public class Member
{
    public static int Challenges { get; set; }
    public static int NicknameId { get; set; }
    public static string LoginId { get; set; }
    public static string FriendsListId { get; set; }

    public static void ClearVariables()
    {
        Challenges = 0;
        NicknameId = 0;
        LoginId = null;
        FriendsListId = null;
    }
}

Global.asax

void Session_End(object sender, EventArgs e) 
    {
        Member.ClearVariables();
    }

My question is, is it safe enough to store user data in a class like this, or should I stick with Session objects?

Updated for Completeness
Will this post do something like above, but for multiple users?
How to access session variables from any class in ASP.NET?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:17:31+00:00Added an answer on June 13, 2026 at 9:17 am

    I found this approach is one of the most easy to use and with least error of chances. I think this is called Facade Design Pattern.

     public class SiteSession
    {
        #region Attributes
        private static string _siteSession = "__SiteSession__";
        #endregion
    
        #region Constructor
        private SiteSession()
        {
        }
        #endregion
    
        #region CurrentSession
        public static SiteSession Current
        {
            get
            {
                SiteSession session = HttpContext.Current.Session[_siteSession ] as    SiteSession;
                if (session == null)
                {
                    session = new SiteSession();
                    HttpContext.Current.Session[_siteSession ] = session;
                }
                return session;
            }
        }
        #endregion
    
        #region SessionProperties
        public sherserve.CustomTypes.UserTypes UserType { get; set; }
        public int UserID { get; set; }
        public String StaffID { get; set; }
        public String Position { get; set; }
        public String StaffName { get; set; }
        public int TimeZone { get; set; }
    
        public String DealerId { get; set; }
        public String DealerPosition { get; set; }
        public String DealerName { get; set; }
        public int DealerFirmId { get; set; }
    
        public String ClientId { get; set; }
        public String ClientName { get; set; }
        public String ClientBusiness { get; set; }
        public String CountryCode { get; set; }
        public int ClientFirmId { get; set; }
        #endregion
    
    }
    

    Values can be store in Session like this:

     SiteSession.Current.UserType = user.UserType;
    

    And Can be obtain like this :

    int userId=    SiteSession.Current.UserID;
    

    It is type safe as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have always wondered how delegates can be useful and why shall we use
I have always thought that in order to connect to SQL server using windows
I have always wondered how programming languages are different, if they are indeed different,
I have always been a bit unclear on the type of tasks that should
I have a program that load data from a file using std::ifstream and store
I have a list of data that users are able to control the sort
I have two parameters in my stored procedure i.e. @startdate and @enddate. The user
I'm writing a application where the user can write json-code and store that json
I have huge data matrices stored in a MATLAB M-file and I will explain
I have this little application, and what it does is a user can add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.