Click here to Skip to main content
12,999,628 members (55,328 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 5 Nov 2013

Use Session Object as Static Class Variables

, 5 Nov 2013
Rate this:
Please Sign up or sign in to vote.
This tip describes the way to use the session object as a static class.


This tip describes the way to use the session object as a static class. The advantage is that you can define all the variables (with their appropriate getters / setters) that you will require and session values can be set / get using . (dot) operator of static class.

Using the Code

You can use session object as static class using the appcode folder. You need to define a static class with its member variables and getters / setters. Just follow the steps given below:

  1. Create a new .cs class in your appcode folder.
  2. Convert the class as static:
    public static class SessionManager 
  3. Declare and define the static variables names:
    private const string SESSION_StageFlag = "StageFlag";
  4. Create the appropriate properties for each variable defined earlier:
    public static string StageFlag
                    if (null != HttpContext.Current.Session[SESSION_StageFlag])
                        return HttpContext.Current.Session[SESSION_StageFlag] as string;
                        return null;
                    HttpContext.Current.Session[SESSION_StageFlag] = value;
  5. Build your project and now you will be able to manipulate the session through SessionManager in your aspx.cs classes. Just add the namespace of your new SessionManager class and it can be accessed as shown below:
    SessionManager.StageFlag = "Fixed" 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Muhammad Waqas Iqbal
Software Developer (Senior) Freelancer
Pakistan Pakistan
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionConcurrency Pin
ExpertITM21-Nov-15 17:58
memberExpertITM21-Nov-15 17:58 
SuggestionFacade Pattern Pin
Richard Deeming12-Nov-13 8:31
professionalRichard Deeming12-Nov-13 8:31 
GeneralRe: Facade Pattern Pin
m.waqasiqbal12-Nov-13 16:55
memberm.waqasiqbal12-Nov-13 16:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 5 Nov 2013
Article Copyright 2013 by Muhammad Waqas Iqbal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid