Session Variables in Static Objects

Discussion in 'ASP .Net' started by james@instantecommerce.co.uk, Mar 21, 2006.

  1. Guest

    Hi

    I am considering storing my session variables within one static object
    with session scope. The static object will be a class with accessor
    functions to get and set the equivalent session variables stored as
    member variables. This will allow strong typing. Apart from the
    problems of multithreading, are there any performance overheards of
    which I should be aware?

    Thanks

    James
     
    , Mar 21, 2006
    #1
    1. Advertising

  2. The way this is normally accomplished is via something like:

    public class User
    {
    private int _userId;
    public int UserId { get { return _userId; } set { _userId = value;} }

    private User(){}

    public static User GetCurrentUser()
    {
    get
    {
    if (HttContext.Current != null &&
    HttpContext.Current.Session["User"] != null)
    {
    return (User)HttContext.Current.Session["User"];
    }
    //throw an error? return an anonymous user?
    }
    }
    }

    This avoids multithreadng issues, and doesn't have any performance
    drawbacks.

    Karl

    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    <> wrote in message
    news:...
    > Hi
    >
    > I am considering storing my session variables within one static object
    > with session scope. The static object will be a class with accessor
    > functions to get and set the equivalent session variables stored as
    > member variables. This will allow strong typing. Apart from the
    > problems of multithreading, are there any performance overheards of
    > which I should be aware?
    >
    > Thanks
    >
    > James
    >
     
    Karl Seguin [MVP], Mar 21, 2006
    #2
    1. Advertising

  3. Webmills Guest

    Thanks very much Karl
     
    Webmills, Mar 21, 2006
    #3
    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:
    1
    Views:
    948
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,446
    Tony Morris
    Oct 19, 2004
  3. gorda
    Replies:
    5
    Views:
    5,064
    akhyls
    Mar 7, 2010
  4. Neviton
    Replies:
    9
    Views:
    473
    Alf P. Steinbach
    Sep 17, 2007
  5. Victor Bazarov
    Replies:
    11
    Views:
    758
    James Kanze
    Dec 9, 2009
Loading...

Share This Page