Accessing session data in a class file- which class do I inherit from?

Discussion in 'ASP .Net' started by Kevin Spencer, Apr 22, 2004.

  1. System.Web.HttpContext.Current.Session

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Charlie@CBFC" <> wrote in message
    news:#...
    > Hi:
    >
    > The code to add items to shopping cart is a seperate class file so I don't
    > have to keep repeating it. If I want to be able to access session data in
    > this class, which class should I base it on?
    >
    > Thanks,
    > Charlie
    >
    >
    Kevin Spencer, Apr 22, 2004
    #1
    1. Advertising

  2. Kevin Spencer

    Matt Berther Guest

    Hello Kevin,

    > System.Web.HttpContext.Current.Session


    Actually, this is the property that he should use. For what he's doing, he has no need to inherit from a class.

    > "Charlie@CBFC" <> wrote in message
    > news:#...
    >
    >> Hi:
    >>
    >> The code to add items to shopping cart is a seperate class file so I
    >> don't have to keep repeating it. If I want to be able to access
    >> session data in this class, which class should I base it on?


    I've posted some code to this group before detailing a singleton implementation of a Session wrapper. Using this code would allow you to use Session state in whatever class you want.

    Take a look at http://groups.google.com/groups?hl=...=&rnum=1

    Hope this answers your question...

    --
    Matt Berther
    http://www.mattberther.com
    Matt Berther, Apr 22, 2004
    #2
    1. Advertising

  3. Kevin Spencer

    Charlie@CBFC Guest

    Hi:

    The code to add items to shopping cart is a seperate class file so I don't
    have to keep repeating it. If I want to be able to access session data in
    this class, which class should I base it on?

    Thanks,
    Charlie
    Charlie@CBFC, Apr 22, 2004
    #3
  4. Inherit from a class?! What I posted was nothing but a static property of
    the System.Web.HttpContext class. No inheritance involved. Simply a complete
    namespace. No wrapper necessary. A wrapper just adds useless overhead.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Matt Berther" <> wrote in message
    news:...
    > Hello Kevin,
    >
    > > System.Web.HttpContext.Current.Session

    >
    > Actually, this is the property that he should use. For what he's doing, he

    has no need to inherit from a class.
    >
    > > "Charlie@CBFC" <> wrote in message
    > > news:#...
    > >
    > >> Hi:
    > >>
    > >> The code to add items to shopping cart is a seperate class file so I
    > >> don't have to keep repeating it. If I want to be able to access
    > >> session data in this class, which class should I base it on?

    >
    > I've posted some code to this group before detailing a singleton

    implementation of a Session wrapper. Using this code would allow you to use
    Session state in whatever class you want.
    >
    > Take a look at

    http://groups.google.com/groups?hl=...=&rnum=1
    >
    > Hope this answers your question...
    >
    > --
    > Matt Berther
    > http://www.mattberther.com
    Kevin Spencer, Apr 22, 2004
    #4
  5. Kevin Spencer

    Matt Berther Guest

    Hello Kevin,

    > Inherit from a class?! What I posted was nothing but a static property
    > of the System.Web.HttpContext class. No inheritance involved. Simply a


    I understand. You have the right answer. However, he was asking about inheriting from a class.

    > complete namespace. No wrapper necessary. A wrapper just adds useless
    > overhead.


    I would disagree with your comment about the wrapper. The code that I posted gives me strongly typed access to my session variables, which is much better for catching errors at compile time.

    --
    Matt Berther
    http://www.mattberther.com
    Matt Berther, Apr 22, 2004
    #5
  6. Kevin Spencer

    Charlie@CBFC Guest

    It would not work using base class- got errors trying to access session
    vars. I then derived it from Page class and it works fine. Just wondering
    if there is a more lightweight class?

    Charlie

    "Matt Berther" <> wrote in message
    news:...
    > Hello Kevin,
    >
    > > System.Web.HttpContext.Current.Session

    >
    > Actually, this is the property that he should use. For what he's doing, he

    has no need to inherit from a class.
    >
    > > "Charlie@CBFC" <> wrote in message
    > > news:#...
    > >
    > >> Hi:
    > >>
    > >> The code to add items to shopping cart is a seperate class file so I
    > >> don't have to keep repeating it. If I want to be able to access
    > >> session data in this class, which class should I base it on?

    >
    > I've posted some code to this group before detailing a singleton

    implementation of a Session wrapper. Using this code would allow you to use
    Session state in whatever class you want.
    >
    > Take a look at

    http://groups.google.com/groups?hl=...=&rnum=1
    >
    > Hope this answers your question...
    >
    > --
    > Matt Berther
    > http://www.mattberther.com
    Charlie@CBFC, Apr 22, 2004
    #6
  7. Kevin Spencer

    Charlie@CBFC Guest

    That worked, thanks!
    "Kevin Spencer" <> wrote in message
    news:%...
    > System.Web.HttpContext.Current.Session
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Charlie@CBFC" <> wrote in message
    > news:#...
    > > Hi:
    > >
    > > The code to add items to shopping cart is a seperate class file so I

    don't
    > > have to keep repeating it. If I want to be able to access session data

    in
    > > this class, which class should I base it on?
    > >
    > > Thanks,
    > > Charlie
    > >
    > >

    >
    >
    Charlie@CBFC, Apr 23, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    355
  2. Replies:
    6
    Views:
    510
  3. DBak
    Replies:
    11
    Views:
    982
  4. Amr
    Replies:
    15
    Views:
    839
    Roedy Green
    Feb 17, 2010
  5. Kamarulnizam Rahim

    class and inheritance. Inherit data

    Kamarulnizam Rahim, Jan 31, 2011, in forum: Ruby
    Replies:
    3
    Views:
    112
    Waldemar Dick
    Feb 1, 2011
Loading...

Share This Page