c# access session in class

public class MySession
{
    // private constructor
    private MySession()
    {
      Property1 = "default value";
    }

    // Gets the current session.
    public static MySession Current
    {
      get
      {
        MySession session =
          (MySession)HttpContext.Current.Session["__MySession__"];
        if (session == null)
        {
          session = new MySession();
          HttpContext.Current.Session["__MySession__"] = session;
        }
        return session;
      }
    }

    // **** add your session properties here, e.g like this:
    public string Property1 { get; set; }
    public DateTime MyDate { get; set; }
    public int LoginId { get; set; }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
How to get session value in C# use session in class file c# access session in static method c# c# session variable session in c# example object in session c# c# session object c# choose session Session are created using c# c# session usage set and get session value in c# session management in c# c# set get session property how to get session variable in c# create session in c# session variables c# c# session variable in class session c# asp get session in c# get session value in c# c# variable session get and set session in c# session object c# GET THE SESSION IN C# c# request session session code in c# using session in service c# inject session c# c# session what is session object and Application object in c# c# session value how do oyu call a session varibel in c# class how to read a session variable in c# C# how to get session object session class c# how to declare a session variable in c# how to use session in c# how to get a session object c# set session value in attribute c# mvc core 5 access session variable in class mvc core access session variable in class how to get session value c# access session from attribute c# asp.net get session c# session using c# access session in class session variable accessible to all request asp.net get session value in class file c# access session in class file c# session in class c# ASP.Net session read in a class c# check session in class get session c# asp net from class get session c# asp.net use session in class access session C# how to use session in c# class ession in class c# access session variable in class .net core c# session specific variable from class c# read session data access resource in js c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source