how to initialise an object to be available for all users? ASP.net

Discussion in 'ASP .Net' started by Annie, Sep 12, 2005.

  1. Annie

    Annie Guest

    hello all,

    is it possible at all?

    i have a class that encapsulates a Hashtable collection. What i want is to
    initialise this object once and only once and
    then be able to access its Public Static methods always.

    What i want is when the user logs in i gets its detail and add him/her in
    the hashtable until her/she is online and similarly
    for next user and so on until they log out or close the browser then i
    remove them from hash table.

    I don't know how to inititialize the object once?
    Is it possible at all?

    TA
    Annie, Sep 12, 2005
    #1
    1. Advertising

  2. Annie

    Guest

    You can initialize the object in the Application_OnStart event and add
    it to the application object, and then in the Session_OnStart event add
    the user information to the object.

    --
    Ahmed Bouagja

    Annie wrote:
    > hello all,
    >
    > is it possible at all?
    >
    > i have a class that encapsulates a Hashtable collection. What i want is to
    > initialise this object once and only once and
    > then be able to access its Public Static methods always.
    >
    > What i want is when the user logs in i gets its detail and add him/her in
    > the hashtable until her/she is online and similarly
    > for next user and so on until they log out or close the browser then i
    > remove them from hash table.
    >
    > I don't know how to inititialize the object once?
    > Is it possible at all?
    >
    > TA
    , Sep 12, 2005
    #2
    1. Advertising

  3. 1. Use a singleton pattern for the object that encapsulates the Hashtable (or
    place it in Application).

    public class SingletonHashtable : Hashtable
    {
    //Cannot instantiate object with constructor
    private SingletonHashtable
    {
    }

    //single static hashtable
    private static SingletonHashtable a;

    public SingletonHashtable GetHashtable()
    {
    if(a==null)
    a = new Hashtable();

    return a;
    }
    }

    2. Add users on Session_Start and get rid of them on Session_End.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ***************************
    Think Outside the Box!
    ***************************


    "Annie" wrote:

    > hello all,
    >
    > is it possible at all?
    >
    > i have a class that encapsulates a Hashtable collection. What i want is to
    > initialise this object once and only once and
    > then be able to access its Public Static methods always.
    >
    > What i want is when the user logs in i gets its detail and add him/her in
    > the hashtable until her/she is online and similarly
    > for next user and so on until they log out or close the browser then i
    > remove them from hash table.
    >
    > I don't know how to inititialize the object once?
    > Is it possible at all?
    >
    > TA
    >
    >
    >
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Sep 12, 2005
    #3
  4. Annie

    Annie Guest

    Hello Cowby,

    Thanks for your reply however I don't think the code you have written will
    work though it compiles ...

    This line

    private static SingletonHashtable a;
    and the line:
    a = new Hashtable();
    are not good i believe?

    variable type is as SingletonHashtable while creating new instance of
    Hashtable.

    It never checks for the null value if(a==null)?? that is what I had the
    problem with ...

    TA

    "Annie" <> wrote in message
    news:43258f09$...
    > hello all,
    >
    > is it possible at all?
    >
    > i have a class that encapsulates a Hashtable collection. What i want is to
    > initialise this object once and only once and
    > then be able to access its Public Static methods always.
    >
    > What i want is when the user logs in i gets its detail and add him/her in
    > the hashtable until her/she is online and similarly
    > for next user and so on until they log out or close the browser then i
    > remove them from hash table.
    >
    > I don't know how to inititialize the object once?
    > Is it possible at all?
    >
    > TA
    >
    Annie, Sep 13, 2005
    #4
    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. MNQ
    Replies:
    4
    Views:
    533
    Tim Hubberstey
    Jun 17, 2004
  2. Replies:
    1
    Views:
    439
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=
    Oct 19, 2005
  3. Nandan
    Replies:
    4
    Views:
    392
    Tor Iver Wilhelmsen
    Apr 29, 2005
  4. Yu
    Replies:
    12
    Views:
    477
    vijay
    Jul 10, 2003
  5. Bernie Beattie

    WebParts - can you transfer one users choice to all users?

    Bernie Beattie, Sep 6, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    103
    Bernie Beattie
    Sep 6, 2006
Loading...

Share This Page