473,414 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

ASP.NET multiple users/ single class files

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
7 2141
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tess | last post by:
Hi, Long time reader, first time poster... Any help is appreciated. I have a few questions regarding Winform controls embedded within an html page. For more info please see the appendix. Now,...
14
by: vishal | last post by:
Is it possible using any tool to get a single C file containing a combined code of multiple C files. The single file should include the contents of the header file. Example if I have following...
6
by: Andrew Connell | last post by:
I have an app where I want virtually everything password protected/secure except for a single directory. That directory handles some custom authentication and contains my login form, but also some...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: PK9 | last post by:
I'm building a windows app using C#. The goal is to merge portions of multiple xml files into one. I currently have an .xsl stylesheet that pulls in the required sections of multiple xml files...
3
by: Michel | last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for the user; the user open my app, do some works and try to open another instance of my app, I whant to show a message to...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.