ASP.NET multiple users/ single class files

Discussion in 'ASP .Net' started by =?Utf-8?B?anNhbGU=?=, Dec 8, 2004.

  1. I have made an ASP.NET web application that connects to SQL Server, reading
    and writing data using classes. I was recommended to use session objects to
    store the data per user, because each user using the application needs to see
    their own data only. My problem is that when multiple users are in the
    application, when in the session object, data is fine, however as there is
    only one instance of the class files, when data is put into them, every
    user's data is mixed. Can classes be used with ASP.NET for this purpose? If
    so, how?!? I'm confused because in Windows applications each user has their
    own executables and class files locally, however in a web application, each
    user uses the same class files - are they replicated in memory or is there
    only the one set of class files? If the latter then surely they will always
    be overwritten.
    Any help would be great, thanks

    For my original problem and the resulting solution, please search on this
    string:
    "Problem with asp.net app only allowing 1 user"
    =?Utf-8?B?anNhbGU=?=, Dec 8, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?anNhbGU=?=

    Hans Kesting Guest

    jsale wrote:
    > I have made an ASP.NET web application that connects to SQL Server,
    > reading and writing data using classes. I was recommended to use
    > session objects to store the data per user, because each user using
    > the application needs to see their own data only. My problem is that
    > when multiple users are in the application, when in the session
    > object, data is fine, however as there is only one instance of the
    > class files, when data is put into them, every user's data is mixed.
    > Can classes be used with ASP.NET for this purpose? If so, how?!? I'm
    > confused because in Windows applications each user has their own
    > executables and class files locally, however in a web application,
    > each user uses the same class files - are they replicated in memory
    > or is there only the one set of class files? If the latter then
    > surely they will always be overwritten.
    > Any help would be great, thanks
    >
    > For my original problem and the resulting solution, please search on
    > this string:
    > "Problem with asp.net app only allowing 1 user"


    If you use a different *instance* for each user, there should not be a problem.
    Only use a singleton if you really mean there should be only one instance
    in the entire application.

    If you are writing information to a temporary file (as you seem to do from
    your other post), then you need to make sure every user (read: session)
    uses a different file. I'm not sure this is the best route though! (performance
    issues, security issues, diskspace, ...)

    I think a better way is:
    - define (in your code) a class to hold all data you want to collect
    - for each session, create an instance of this class and store it in Session
    - if you want to store some data in that object, retrieve a reference to
    it from the Session and update you object.
    - when you are ready to store everything (for this user) in the database,
    again retrieve a reference, read everything and store it in the database.
    Then you can remove this object from the user's Session.

    The fact that the *code* is shared in the web-application doesn't mean that
    the *values* are shared too. Unless you specifically want to, that is.

    Show some code how you persist that temporary data now, and we can point
    out specific issues with it.

    Hans Kesting
    Hans Kesting, Dec 8, 2004
    #2
    1. Advertising

  3. I'm not using singletons, what I meant was that when I created the web
    application, the folder houses a number of web pages (aspx pages) as well as
    class files. When a user uses my application and selects a site from the
    database, a functions module retrieves the data and creates a new instance of
    the class (housed in a class collection) where required. I can't really put
    any meaningful code on here for you because the many different classes are
    100s lines of code each!
    By 'single instance', i meant that the classes only exist on the web server,
    not on seperate computers like windows applications where each user has their
    local copy.

    "Hans Kesting" wrote:

    > jsale wrote:
    > > I have made an ASP.NET web application that connects to SQL Server,
    > > reading and writing data using classes. I was recommended to use
    > > session objects to store the data per user, because each user using
    > > the application needs to see their own data only. My problem is that
    > > when multiple users are in the application, when in the session
    > > object, data is fine, however as there is only one instance of the
    > > class files, when data is put into them, every user's data is mixed.
    > > Can classes be used with ASP.NET for this purpose? If so, how?!? I'm
    > > confused because in Windows applications each user has their own
    > > executables and class files locally, however in a web application,
    > > each user uses the same class files - are they replicated in memory
    > > or is there only the one set of class files? If the latter then
    > > surely they will always be overwritten.
    > > Any help would be great, thanks
    > >
    > > For my original problem and the resulting solution, please search on
    > > this string:
    > > "Problem with asp.net app only allowing 1 user"

    >
    > If you use a different *instance* for each user, there should not be a problem.
    > Only use a singleton if you really mean there should be only one instance
    > in the entire application.
    >
    > If you are writing information to a temporary file (as you seem to do from
    > your other post), then you need to make sure every user (read: session)
    > uses a different file. I'm not sure this is the best route though! (performance
    > issues, security issues, diskspace, ...)
    >
    > I think a better way is:
    > - define (in your code) a class to hold all data you want to collect
    > - for each session, create an instance of this class and store it in Session
    > - if you want to store some data in that object, retrieve a reference to
    > it from the Session and update you object.
    > - when you are ready to store everything (for this user) in the database,
    > again retrieve a reference, read everything and store it in the database.
    > Then you can remove this object from the user's Session.
    >
    > The fact that the *code* is shared in the web-application doesn't mean that
    > the *values* are shared too. Unless you specifically want to, that is.
    >
    > Show some code how you persist that temporary data now, and we can point
    > out specific issues with it.
    >
    > Hans Kesting
    >
    >
    >
    =?Utf-8?B?anNhbGU=?=, Dec 8, 2004
    #3
  4. If i can explain a little better, i don't use singletons, it's just that
    whereas a windows application has a local copy (i.e. one per user) of all the
    classes, only the one user is writing to them. With the web application, the
    confusion i am getting is that the web server only has one physical copy of
    the classes, but is accessed many times by many users, therefore, how does it
    'know' which user is using the classes at any one time?
    The sort of structure i am using is that when data is retrieved from the DB,
    it is stored in class files, which in turn are saved into session objects (so
    each user has their and only their data available):
    Session("Project") = Project 'where project is the main class
    The problem is that when the data is taken out of the session and put back
    into the classes for amendment, any subsequent users using the classes at the
    time are looking at the 1st users' data.
    Sorry if i'm not making myself clear, i'm trying to get my head around this
    as well. Thanks for replying!

    "Hans Kesting" wrote:

    > jsale wrote:
    > > I have made an ASP.NET web application that connects to SQL Server,
    > > reading and writing data using classes. I was recommended to use
    > > session objects to store the data per user, because each user using
    > > the application needs to see their own data only. My problem is that
    > > when multiple users are in the application, when in the session
    > > object, data is fine, however as there is only one instance of the
    > > class files, when data is put into them, every user's data is mixed.
    > > Can classes be used with ASP.NET for this purpose? If so, how?!? I'm
    > > confused because in Windows applications each user has their own
    > > executables and class files locally, however in a web application,
    > > each user uses the same class files - are they replicated in memory
    > > or is there only the one set of class files? If the latter then
    > > surely they will always be overwritten.
    > > Any help would be great, thanks
    > >
    > > For my original problem and the resulting solution, please search on
    > > this string:
    > > "Problem with asp.net app only allowing 1 user"

    >
    > If you use a different *instance* for each user, there should not be a problem.
    > Only use a singleton if you really mean there should be only one instance
    > in the entire application.
    >
    > If you are writing information to a temporary file (as you seem to do from
    > your other post), then you need to make sure every user (read: session)
    > uses a different file. I'm not sure this is the best route though! (performance
    > issues, security issues, diskspace, ...)
    >
    > I think a better way is:
    > - define (in your code) a class to hold all data you want to collect
    > - for each session, create an instance of this class and store it in Session
    > - if you want to store some data in that object, retrieve a reference to
    > it from the Session and update you object.
    > - when you are ready to store everything (for this user) in the database,
    > again retrieve a reference, read everything and store it in the database.
    > Then you can remove this object from the user's Session.
    >
    > The fact that the *code* is shared in the web-application doesn't mean that
    > the *values* are shared too. Unless you specifically want to, that is.
    >
    > Show some code how you persist that temporary data now, and we can point
    > out specific issues with it.
    >
    > Hans Kesting
    >
    >
    >
    =?Utf-8?B?anNhbGU=?=, Dec 8, 2004
    #4
  5. =?Utf-8?B?anNhbGU=?=

    Hans Kesting Guest

    jsale wrote:
    > I'm not using singletons, what I meant was that when I created the web
    > application, the folder houses a number of web pages (aspx pages) as
    > well as class files. When a user uses my application and selects a
    > site from the database, a functions module retrieves the data and
    > creates a new instance of the class (housed in a class collection)
    > where required. I can't really put any meaningful code on here for
    > you because the many different classes are 100s lines of code each!
    > By 'single instance', i meant that the classes only exist on the web
    > server, not on seperate computers like windows applications where
    > each user has their local copy.
    >


    You need to make a distinction between "code that defines a class"
    and "instance of a class". With that single copy of the class-code you can create
    any number of independent instances:

    -------------------
    class MyClass
    {
    public int val;
    }

    MyClass c1 = new MyClass();
    MyClass c2 = new MyClass();

    c1.val = 1;
    c2.val = 2;

    Console.WriteLine(c1.ToString()); <---- gives 1
    Console.WriteLine(c2.ToString()); <---- gives 2
    ------------------
    Can you show some *example* code how you are updating
    user-specific values (where you apparently get values of a different user)?

    Hans Kesting


    > "Hans Kesting" wrote:
    >
    >> jsale wrote:
    >>> I have made an ASP.NET web application that connects to SQL Server,
    >>> reading and writing data using classes. I was recommended to use
    >>> session objects to store the data per user, because each user using
    >>> the application needs to see their own data only. My problem is that
    >>> when multiple users are in the application, when in the session
    >>> object, data is fine, however as there is only one instance of the
    >>> class files, when data is put into them, every user's data is mixed.
    >>> Can classes be used with ASP.NET for this purpose? If so, how?!? I'm
    >>> confused because in Windows applications each user has their own
    >>> executables and class files locally, however in a web application,
    >>> each user uses the same class files - are they replicated in memory
    >>> or is there only the one set of class files? If the latter then
    >>> surely they will always be overwritten.
    >>> Any help would be great, thanks
    >>>
    >>> For my original problem and the resulting solution, please search on
    >>> this string:
    >>> "Problem with asp.net app only allowing 1 user"

    >>
    >> If you use a different *instance* for each user, there should not be
    >> a problem. Only use a singleton if you really mean there should be
    >> only one instance
    >> in the entire application.
    >>
    >> If you are writing information to a temporary file (as you seem to
    >> do from your other post), then you need to make sure every user
    >> (read: session)
    >> uses a different file. I'm not sure this is the best route though!
    >> (performance issues, security issues, diskspace, ...)
    >>
    >> I think a better way is:
    >> - define (in your code) a class to hold all data you want to collect
    >> - for each session, create an instance of this class and store it in
    >> Session
    >> - if you want to store some data in that object, retrieve a
    >> reference to it from the Session and update you object.
    >> - when you are ready to store everything (for this user) in the
    >> database, again retrieve a reference, read everything and store it
    >> in the database. Then you can remove this object from the user's
    >> Session.
    >>
    >> The fact that the *code* is shared in the web-application doesn't
    >> mean that the *values* are shared too. Unless you specifically want
    >> to, that is.
    >>
    >> Show some code how you persist that temporary data now, and we can
    >> point
    >> out specific issues with it.
    >>
    >> Hans Kesting
    Hans Kesting, Dec 8, 2004
    #5
  6. Looks like you are misunderstanding the whole idea how web servers work. It
    is not like there is one instance of your program running all the time and
    serving all requests. Web servers serve http requests. When a request comes,
    server starts your program, builds a response, sends it back to client and
    disposes your program. Your objects get killed at that stage. When another
    request comes, your program will be called another time and new objects will
    be created.

    Eliyahu

    "jsale" <> wrote in message
    news:...
    > I'm not using singletons, what I meant was that when I created the web
    > application, the folder houses a number of web pages (aspx pages) as well

    as
    > class files. When a user uses my application and selects a site from the
    > database, a functions module retrieves the data and creates a new instance

    of
    > the class (housed in a class collection) where required. I can't really

    put
    > any meaningful code on here for you because the many different classes are
    > 100s lines of code each!
    > By 'single instance', i meant that the classes only exist on the web

    server,
    > not on seperate computers like windows applications where each user has

    their
    > local copy.
    >
    > "Hans Kesting" wrote:
    >
    > > jsale wrote:
    > > > I have made an ASP.NET web application that connects to SQL Server,
    > > > reading and writing data using classes. I was recommended to use
    > > > session objects to store the data per user, because each user using
    > > > the application needs to see their own data only. My problem is that
    > > > when multiple users are in the application, when in the session
    > > > object, data is fine, however as there is only one instance of the
    > > > class files, when data is put into them, every user's data is mixed.
    > > > Can classes be used with ASP.NET for this purpose? If so, how?!? I'm
    > > > confused because in Windows applications each user has their own
    > > > executables and class files locally, however in a web application,
    > > > each user uses the same class files - are they replicated in memory
    > > > or is there only the one set of class files? If the latter then
    > > > surely they will always be overwritten.
    > > > Any help would be great, thanks
    > > >
    > > > For my original problem and the resulting solution, please search on
    > > > this string:
    > > > "Problem with asp.net app only allowing 1 user"

    > >
    > > If you use a different *instance* for each user, there should not be a

    problem.
    > > Only use a singleton if you really mean there should be only one

    instance
    > > in the entire application.
    > >
    > > If you are writing information to a temporary file (as you seem to do

    from
    > > your other post), then you need to make sure every user (read: session)
    > > uses a different file. I'm not sure this is the best route though!

    (performance
    > > issues, security issues, diskspace, ...)
    > >
    > > I think a better way is:
    > > - define (in your code) a class to hold all data you want to collect
    > > - for each session, create an instance of this class and store it in

    Session
    > > - if you want to store some data in that object, retrieve a reference to
    > > it from the Session and update you object.
    > > - when you are ready to store everything (for this user) in the

    database,
    > > again retrieve a reference, read everything and store it in the

    database.
    > > Then you can remove this object from the user's Session.
    > >
    > > The fact that the *code* is shared in the web-application doesn't mean

    that
    > > the *values* are shared too. Unless you specifically want to, that is.
    > >
    > > Show some code how you persist that temporary data now, and we can point
    > > out specific issues with it.
    > >
    > > Hans Kesting
    > >
    > >
    > >
    Eliyahu Goldin, Dec 8, 2004
    #6
  7. =?Utf-8?B?anNhbGU=?=

    Matt Berther Guest

    Hello jsale,

    If you are using static variables on the classes in questions, this could
    be a cause of your problem.

    --
    Matt Berther
    http://www.mattberther.com

    > If i can explain a little better, i don't use singletons, it's just
    > that
    > whereas a windows application has a local copy (i.e. one per user) of
    > all the
    > classes, only the one user is writing to them. With the web
    > application, the
    > confusion i am getting is that the web server only has one physical
    > copy of
    > the classes, but is accessed many times by many users, therefore, how
    > does it
    > 'know' which user is using the classes at any one time?
    > The sort of structure i am using is that when data is retrieved from
    > the DB,
    > it is stored in class files, which in turn are saved into session
    > objects (so
    > each user has their and only their data available):
    > Session("Project") = Project 'where project is the main class
    > The problem is that when the data is taken out of the session and put
    > back
    > into the classes for amendment, any subsequent users using the classes
    > at the
    > time are looking at the 1st users' data.
    > Sorry if i'm not making myself clear, i'm trying to get my head around
    > this
    > as well. Thanks for replying!
    > "Hans Kesting" wrote:
    >
    >> jsale wrote:
    >>
    >>> I have made an ASP.NET web application that connects to SQL Server,
    >>> reading and writing data using classes. I was recommended to use
    >>> session objects to store the data per user, because each user using
    >>> the application needs to see their own data only. My problem is that
    >>> when multiple users are in the application, when in the session
    >>> object, data is fine, however as there is only one instance of the
    >>> class files, when data is put into them, every user's data is mixed.
    >>> Can classes be used with ASP.NET for this purpose? If so, how?!? I'm
    >>> confused because in Windows applications each user has their own
    >>> executables and class files locally, however in a web application,
    >>> each user uses the same class files - are they replicated in memory
    >>> or is there only the one set of class files? If the latter then
    >>> surely they will always be overwritten.
    >>> Any help would be great, thanks
    >>> For my original problem and the resulting solution, please search on
    >>> this string:
    >>> "Problem with asp.net app only allowing 1 user"

    >> If you use a different *instance* for each user, there should not be
    >> a problem.
    >> Only use a singleton if you really mean there should be only one
    >> instance
    >> in the entire application.
    >> If you are writing information to a temporary file (as you seem to do
    >> from
    >> your other post), then you need to make sure every user (read:
    >> session)
    >> uses a different file. I'm not sure this is the best route though!
    >> (performance
    >> issues, security issues, diskspace, ...)
    >> I think a better way is:
    >> - define (in your code) a class to hold all data you want to collect
    >> - for each session, create an instance of this class and store it in
    >> Session
    >> - if you want to store some data in that object, retrieve a reference
    >> to
    >> it from the Session and update you object.
    >> - when you are ready to store everything (for this user) in the
    >> database,
    >> again retrieve a reference, read everything and store it in the
    >> database.
    >> Then you can remove this object from the user's Session.
    >> The fact that the *code* is shared in the web-application doesn't
    >> mean that the *values* are shared too. Unless you specifically want
    >> to, that is.
    >>
    >> Show some code how you persist that temporary data now, and we can
    >> point out specific issues with it.
    >>
    >> Hans Kesting
    >>
    Matt Berther, Dec 9, 2004
    #7
  8. =?Utf-8?B?anNhbGU=?=

    Hans Kesting Guest

    Hans Kesting wrote:
    > jsale wrote:
    >> I'm not using singletons, what I meant was that when I created the
    >> web application, the folder houses a number of web pages (aspx
    >> pages) as well as class files. When a user uses my application and
    >> selects a site from the database, a functions module retrieves the
    >> data and creates a new instance of the class (housed in a class
    >> collection) where required. I can't really put any meaningful code
    >> on here for you because the many different classes are 100s lines of
    >> code each! By 'single instance', i meant that the classes only exist
    >> on the web server, not on seperate computers like windows
    >> applications where each user has their local copy.
    >>

    >
    > You need to make a distinction between "code that defines a class"
    > and "instance of a class". With that single copy of the class-code
    > you can create any number of independent instances:
    >
    > -------------------
    > class MyClass
    > {
    > public int val;
    > }
    >
    > MyClass c1 = new MyClass();
    > MyClass c2 = new MyClass();
    >
    > c1.val = 1;
    > c2.val = 2;
    >
    > Console.WriteLine(c1.ToString()); <---- gives 1


    eh, this should have been
    Console.WriteLine(c1.val.ToString());

    > Console.WriteLine(c2.ToString()); <---- gives 2


    Console.WriteLine(c2.val.ToString());

    > ------------------
    > Can you show some *example* code how you are updating
    > user-specific values (where you apparently get values of a different
    > user)?
    > Hans Kesting
    >
    >
    >> "Hans Kesting" wrote:
    >>
    >>> jsale wrote:
    >>>> I have made an ASP.NET web application that connects to SQL Server,
    >>>> reading and writing data using classes. I was recommended to use
    >>>> session objects to store the data per user, because each user using
    >>>> the application needs to see their own data only. My problem is
    >>>> that when multiple users are in the application, when in the
    >>>> session object, data is fine, however as there is only one
    >>>> instance of the class files, when data is put into them, every
    >>>> user's data is mixed. Can classes be used with ASP.NET for this
    >>>> purpose? If so, how?!? I'm confused because in Windows
    >>>> applications each user has their own executables and class files
    >>>> locally, however in a web application, each user uses the same
    >>>> class files - are they replicated in memory or is there only the
    >>>> one set of class files? If the latter then surely they will always
    >>>> be overwritten. Any help would be great, thanks
    >>>>
    >>>> For my original problem and the resulting solution, please search
    >>>> on this string:
    >>>> "Problem with asp.net app only allowing 1 user"
    >>>
    >>> If you use a different *instance* for each user, there should not be
    >>> a problem. Only use a singleton if you really mean there should be
    >>> only one instance
    >>> in the entire application.
    >>>
    >>> If you are writing information to a temporary file (as you seem to
    >>> do from your other post), then you need to make sure every user
    >>> (read: session)
    >>> uses a different file. I'm not sure this is the best route though!
    >>> (performance issues, security issues, diskspace, ...)
    >>>
    >>> I think a better way is:
    >>> - define (in your code) a class to hold all data you want to collect
    >>> - for each session, create an instance of this class and store it in
    >>> Session
    >>> - if you want to store some data in that object, retrieve a
    >>> reference to it from the Session and update you object.
    >>> - when you are ready to store everything (for this user) in the
    >>> database, again retrieve a reference, read everything and store it
    >>> in the database. Then you can remove this object from the user's
    >>> Session.
    >>>
    >>> The fact that the *code* is shared in the web-application doesn't
    >>> mean that the *values* are shared too. Unless you specifically want
    >>> to, that is.
    >>>
    >>> Show some code how you persist that temporary data now, and we can
    >>> point
    >>> out specific issues with it.
    >>>
    >>> Hans Kesting
    Hans Kesting, Dec 9, 2004
    #8
    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. Chris
    Replies:
    1
    Views:
    13,610
    Oisin
    Mar 24, 2006
  2. Replies:
    4
    Views:
    938
    M.E.Farmer
    Feb 13, 2005
  3. bitshift
    Replies:
    1
    Views:
    530
    bruce barker
    Jun 22, 2007
  4. Niranjan
    Replies:
    0
    Views:
    309
    Niranjan
    May 21, 2004
  5. ela
    Replies:
    12
    Views:
    334
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page