By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

ASP.NET multiple users/ single class files

P: n/a
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"
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
Nov 19 '05 #2

P: n/a
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

Nov 19 '05 #3

P: n/a
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

Nov 19 '05 #4

P: n/a
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" <js***@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
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

Nov 19 '05 #5

P: n/a
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

Nov 19 '05 #6

P: n/a
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

Nov 19 '05 #7

P: n/a
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

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.