473,721 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with asp.net app only allowing 1 user at a time

I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the database into classes, which are used
throughout the application. I have made class collections which, upon reading
from the DB, create an instance of the class and store the DB values in
there temporarily. My problem is that if user1 looks at record1, then user2
looks at record2, anything user1 does from that point onwards points the data
at record2.
Is there anything in particular i need to do to make the asp.net application
available to multiple users at the same time, each looking at different
records in the DB?
Thanks in advance
Nov 19 '05 #1
7 2915
If I'm understanding you correctly you are loading data for the user
from the database then storing that data into application scope. The
issue that you then have is that you retrieve this data from application
scope the next time the page is displayed. If this is the case then you
should modify the way you are handling state management.

The Application object should only be used to store data that is truly
global to every user of the application. If you need to store things on
a per user basis you should look into using the Session object. Using
the Session object will allow you to store data classes on a per user
basis.

If you are worried about running the same query against the database
multiple times, then you might want to abstract the use of the
Application object (not a bad idea in general anyway) so that you can
store a collection of query result sets keyed by the query used, then
retrieve the appropriate result set for each user from the collection.
If the collection doesn't contain the appropriate result set then you
query the database and then add it to the collection and put the
collection back in Application scope. Once you retrieve the appropriate
result set from the application collection you could then put it in the
user's Session object and continue your retrieval from there.

Without more information on how you really intend to use these objects
it is hard to know which solution to use, but hopefully something from
the above will work for you.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the database into classes, which are used
throughout the application. I have made class collections which, upon reading
from the DB, create an instance of the class and store the DB values in
there temporarily. My problem is that if user1 looks at record1, then user2
looks at record2, anything user1 does from that point onwards points the data
at record2.
Is there anything in particular i need to do to make the asp.net application
available to multiple users at the same time, each looking at different
records in the DB?
Thanks in advance

Nov 19 '05 #2
I'm kinda new to professional asp.net development, so could you just clarify
the application and session objects?
I've got a module that houses many functions that all retrieve information
about their specific table from the database, writing the information into a
'.vb' class file. In effect, i am taking a snapshot of the database at that
current moment and storing it to the class, amending it there and then
writing changes back to the database afterwards. If i understand you
correctly, that is application level, therefore every user's instance of the
application sees the same data, whereas on a session level, each user would
see their own instance. Is this correct? If so, do you have any pointers
about making class files per session, not per application? I'm hugely
confused! The reason i'm developing like this is because i'm migrating an old
VB6 app and web-enabling it using ASP.NET. The old version used classes and i
was expected to re-use as much as possible. I think i understand that the
inherent difference is that with the old app it was installed seperately on
each computer, whereas the ASP.NET version is just one copy, installed on the
web server.
Any help would be gratefully receieved :)

"John M Deal" wrote:
If I'm understanding you correctly you are loading data for the user
from the database then storing that data into application scope. The
issue that you then have is that you retrieve this data from application
scope the next time the page is displayed. If this is the case then you
should modify the way you are handling state management.

The Application object should only be used to store data that is truly
global to every user of the application. If you need to store things on
a per user basis you should look into using the Session object. Using
the Session object will allow you to store data classes on a per user
basis.

If you are worried about running the same query against the database
multiple times, then you might want to abstract the use of the
Application object (not a bad idea in general anyway) so that you can
store a collection of query result sets keyed by the query used, then
retrieve the appropriate result set for each user from the collection.
If the collection doesn't contain the appropriate result set then you
query the database and then add it to the collection and put the
collection back in Application scope. Once you retrieve the appropriate
result set from the application collection you could then put it in the
user's Session object and continue your retrieval from there.

Without more information on how you really intend to use these objects
it is hard to know which solution to use, but hopefully something from
the above will work for you.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the database into classes, which are used
throughout the application. I have made class collections which, upon reading
from the DB, create an instance of the class and store the DB values in
there temporarily. My problem is that if user1 looks at record1, then user2
looks at record2, anything user1 does from that point onwards points the data
at record2.
Is there anything in particular i need to do to make the asp.net application
available to multiple users at the same time, each looking at different
records in the DB?
Thanks in advance

Nov 19 '05 #3
I really wish I had more time to get into this in depth, but I'm at work
right now so I'll have to keep this short and rely on your ability to
run with this info.

In ASP.Net (and classic ASP for that matter) there are a number of
intrinsic/built-in object provided globally by the environment itself.
Included in these objects is Response (the object that can send data
back to the client), Request (the object that contains the data sent
from the client to the server), Application (an object that can store
globally available data), and Session (an object that can store user
specific data). There are others but these will get you started. You
do not need to create these objects, you simply need to refer to them in
your code.

Now in your case you are reading and writing everything to the database,
so my original notes may not apply in your situation, you'll have to
decide that. However if you do decide to try and follow what I said
before you should know a couple of things.

First Application is created when the web application first starts up
and is available until the web application shuts down. You can catch
events that tell you when these happen in the Global.asax file(s).
You'll want to look into this because if you don't prepare your code for
it data may disappear during long periods of user inactivity and you may
want to reload it when the application reloads. The Application object
can be accessed by any of the connections/threads that are currently
active on the server. This means that you need to lock the access to the
Application object when modifying its contents so you don't run into
threading problems; to do this use Application.Loc k() before you add
something to it and Application.Unl ock() after you are done with it. Any
page that works with the Application object will be using data that is
available to all users connected to the system.

Second, there is the Session object. By default session only lasts
twenty minutes from the last time a user accessed the system (the server
does not have any other way to know if the user is still connected other
than if they make a request). This time limitation can be controlled in
the web.config file for the site. Session is only valid for a single
user connected to the system, however be aware that if the user opens
two separate browsers each one will have its own session (unless one was
launched from another then they share the same session). Session uses a
cookie by default to track an unique id that is used to retrieve data
for the specific user that it is associated to. When you store object
instances in Session they are only stored for (and retrievable by) the
browser instance associated to the unique id. Session can be made to
not require cookies (but then it puts the unique id in the querystring
for the page). Also Session can be configured to store its data in
memory (InProc) in an out of process Service (StateServer) or in an
external database (SqlServer). This is controlled by your web.config
file for the website (as is the session timeout). If you choose to
store session anywhere besides InProc (the default) you will have to
makes sure any object that you store in it is serializable or the system
will throw an exception (it uses serialization to marshal the object
across the process boundary between the site and the storage repository).

Now that all being said. Whether you use Application or Session you
store instances of objects (or primitives if you want) using a
name/value methodology. For example if you have an instance of an User
object called myUser and you want to put it in session you would do
something like (C# code):

Session["TheUserObjectK ey"] = myUser;

To retrieve this you would do something like:

User myUser = (User) Session["TheUserObjectK ey"];

This would work the same for the Application though you'd want to do the
Lock/Unlock pattern that I mentioned before. Also note that because
Application and Session store the base Object type you have to cast your
object back to the appropriate type when retrieving them back out.

Ok, that ran a bit longer than I thought it would but it is the basics
of how these objects work. Now if you want to store objects for the
users, you will want to see if their Session has an instance of your
data object, if it doesn't you'd query it from the database then put it
in Session, if it does you'll want to retrieve it from session and
display the appropriate values. Obviously you'll have to deal with the
issues involved with updating these data objects (if that is necessary
for your circumstances) and also you must realize that because
Application and Session have timeouts you will have objects hanging out
in memory until they expire (and then until the GC collects the object)
but this is standard for ASP.Net applications.

Hopefully this is enough to get you started. See the help files and
MSDN online documentation for more information. If you are looking to
do enterprise development in ASP.Net I'd really recommend that you
pickup a good ASP.Net book (search this newsgroup I'm sure you'll find
plenty of recommendations ). Also there are some webcasts being done on
ASP.Net out on Microsoft's site that might give you some pointers. Hope
something here helps.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm kinda new to professional asp.net development, so could you just clarify
the application and session objects?
I've got a module that houses many functions that all retrieve information
about their specific table from the database, writing the information into a
'.vb' class file. In effect, i am taking a snapshot of the database at that
current moment and storing it to the class, amending it there and then
writing changes back to the database afterwards. If i understand you
correctly, that is application level, therefore every user's instance of the
application sees the same data, whereas on a session level, each user would
see their own instance. Is this correct? If so, do you have any pointers
about making class files per session, not per application? I'm hugely
confused! The reason i'm developing like this is because i'm migrating an old
VB6 app and web-enabling it using ASP.NET. The old version used classes and i
was expected to re-use as much as possible. I think i understand that the
inherent difference is that with the old app it was installed seperately on
each computer, whereas the ASP.NET version is just one copy, installed on the
web server.
Any help would be gratefully receieved :)

"John M Deal" wrote:

If I'm understanding you correctly you are loading data for the user
from the database then storing that data into application scope. The
issue that you then have is that you retrieve this data from application
scope the next time the page is displayed. If this is the case then you
should modify the way you are handling state management.

The Application object should only be used to store data that is truly
global to every user of the application. If you need to store things on
a per user basis you should look into using the Session object. Using
the Session object will allow you to store data classes on a per user
basis.

If you are worried about running the same query against the database
multiple times, then you might want to abstract the use of the
Application object (not a bad idea in general anyway) so that you can
store a collection of query result sets keyed by the query used, then
retrieve the appropriate result set for each user from the collection.
If the collection doesn't contain the appropriate result set then you
query the database and then add it to the collection and put the
collection back in Application scope. Once you retrieve the appropriate
result set from the application collection you could then put it in the
user's Session object and continue your retrieval from there.

Without more information on how you really intend to use these objects
it is hard to know which solution to use, but hopefully something from
the above will work for you.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the database into classes, which are used
throughout the application. I have made class collections which, upon reading
from the DB, create an instance of the class and store the DB values in
there temporarily. My problem is that if user1 looks at record1, then user2
looks at record2, anything user1 does from that point onwards points the data
at record2.
Is there anything in particular i need to do to make the asp.net application
available to multiple users at the same time, each looking at different
records in the DB?
Thanks in advance

Nov 19 '05 #4
John, thanks so much for replying, I can't believe you're in work and sending
such long replies :)
That has helped a great deal, but one last thing, you said that session is
valid for only one user logged in, does that mean that each user can have
their own session, and each session can only be viewed by the one user?
Thanks again :)

"John M Deal" wrote:
I really wish I had more time to get into this in depth, but I'm at work
right now so I'll have to keep this short and rely on your ability to
run with this info.

In ASP.Net (and classic ASP for that matter) there are a number of
intrinsic/built-in object provided globally by the environment itself.
Included in these objects is Response (the object that can send data
back to the client), Request (the object that contains the data sent
from the client to the server), Application (an object that can store
globally available data), and Session (an object that can store user
specific data). There are others but these will get you started. You
do not need to create these objects, you simply need to refer to them in
your code.

Now in your case you are reading and writing everything to the database,
so my original notes may not apply in your situation, you'll have to
decide that. However if you do decide to try and follow what I said
before you should know a couple of things.

First Application is created when the web application first starts up
and is available until the web application shuts down. You can catch
events that tell you when these happen in the Global.asax file(s).
You'll want to look into this because if you don't prepare your code for
it data may disappear during long periods of user inactivity and you may
want to reload it when the application reloads. The Application object
can be accessed by any of the connections/threads that are currently
active on the server. This means that you need to lock the access to the
Application object when modifying its contents so you don't run into
threading problems; to do this use Application.Loc k() before you add
something to it and Application.Unl ock() after you are done with it. Any
page that works with the Application object will be using data that is
available to all users connected to the system.

Second, there is the Session object. By default session only lasts
twenty minutes from the last time a user accessed the system (the server
does not have any other way to know if the user is still connected other
than if they make a request). This time limitation can be controlled in
the web.config file for the site. Session is only valid for a single
user connected to the system, however be aware that if the user opens
two separate browsers each one will have its own session (unless one was
launched from another then they share the same session). Session uses a
cookie by default to track an unique id that is used to retrieve data
for the specific user that it is associated to. When you store object
instances in Session they are only stored for (and retrievable by) the
browser instance associated to the unique id. Session can be made to
not require cookies (but then it puts the unique id in the querystring
for the page). Also Session can be configured to store its data in
memory (InProc) in an out of process Service (StateServer) or in an
external database (SqlServer). This is controlled by your web.config
file for the website (as is the session timeout). If you choose to
store session anywhere besides InProc (the default) you will have to
makes sure any object that you store in it is serializable or the system
will throw an exception (it uses serialization to marshal the object
across the process boundary between the site and the storage repository).

Now that all being said. Whether you use Application or Session you
store instances of objects (or primitives if you want) using a
name/value methodology. For example if you have an instance of an User
object called myUser and you want to put it in session you would do
something like (C# code):

Session["TheUserObjectK ey"] = myUser;

To retrieve this you would do something like:

User myUser = (User) Session["TheUserObjectK ey"];

This would work the same for the Application though you'd want to do the
Lock/Unlock pattern that I mentioned before. Also note that because
Application and Session store the base Object type you have to cast your
object back to the appropriate type when retrieving them back out.

Ok, that ran a bit longer than I thought it would but it is the basics
of how these objects work. Now if you want to store objects for the
users, you will want to see if their Session has an instance of your
data object, if it doesn't you'd query it from the database then put it
in Session, if it does you'll want to retrieve it from session and
display the appropriate values. Obviously you'll have to deal with the
issues involved with updating these data objects (if that is necessary
for your circumstances) and also you must realize that because
Application and Session have timeouts you will have objects hanging out
in memory until they expire (and then until the GC collects the object)
but this is standard for ASP.Net applications.

Hopefully this is enough to get you started. See the help files and
MSDN online documentation for more information. If you are looking to
do enterprise development in ASP.Net I'd really recommend that you
pickup a good ASP.Net book (search this newsgroup I'm sure you'll find
plenty of recommendations ). Also there are some webcasts being done on
ASP.Net out on Microsoft's site that might give you some pointers. Hope
something here helps.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm kinda new to professional asp.net development, so could you just clarify
the application and session objects?
I've got a module that houses many functions that all retrieve information
about their specific table from the database, writing the information into a
'.vb' class file. In effect, i am taking a snapshot of the database at that
current moment and storing it to the class, amending it there and then
writing changes back to the database afterwards. If i understand you
correctly, that is application level, therefore every user's instance of the
application sees the same data, whereas on a session level, each user would
see their own instance. Is this correct? If so, do you have any pointers
about making class files per session, not per application? I'm hugely
confused! The reason i'm developing like this is because i'm migrating an old
VB6 app and web-enabling it using ASP.NET. The old version used classes and i
was expected to re-use as much as possible. I think i understand that the
inherent difference is that with the old app it was installed seperately on
each computer, whereas the ASP.NET version is just one copy, installed on the
web server.
Any help would be gratefully receieved :)

"John M Deal" wrote:

If I'm understanding you correctly you are loading data for the user
from the database then storing that data into application scope. The
issue that you then have is that you retrieve this data from application
scope the next time the page is displayed. If this is the case then you
should modify the way you are handling state management.

The Application object should only be used to store data that is truly
global to every user of the application. If you need to store things on
a per user basis you should look into using the Session object. Using
the Session object will allow you to store data classes on a per user
basis.

If you are worried about running the same query against the database
multiple times, then you might want to abstract the use of the
Application object (not a bad idea in general anyway) so that you can
store a collection of query result sets keyed by the query used, then
retrieve the appropriate result set for each user from the collection.
If the collection doesn't contain the appropriate result set then you
query the database and then add it to the collection and put the
collection back in Application scope. Once you retrieve the appropriate
result set from the application collection you could then put it in the
user's Session object and continue your retrieval from there.

Without more information on how you really intend to use these objects
it is hard to know which solution to use, but hopefully something from
the above will work for you.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:

I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the database into classes, which are used
throughout the application. I have made class collections which, upon reading
from the DB, create an instance of the class and store the DB values in
there temporarily. My problem is that if user1 looks at record1, then user2
looks at record2, anything user1 does from that point onwards points the data
at record2.
Is there anything in particular i need to do to make the asp.net application
available to multiple users at the same time, each looking at different
records in the DB?
Thanks in advance

Nov 19 '05 #5
Finally (soooo sorry for carrying on!) is there a way of adding whole classes
to session and reading out of them, or does each variable have to be at
session level?
Cheers again,
Max

"jsale" wrote:
John, thanks so much for replying, I can't believe you're in work and sending
such long replies :)
That has helped a great deal, but one last thing, you said that session is
valid for only one user logged in, does that mean that each user can have
their own session, and each session can only be viewed by the one user?
Thanks again :)

"John M Deal" wrote:
I really wish I had more time to get into this in depth, but I'm at work
right now so I'll have to keep this short and rely on your ability to
run with this info.

In ASP.Net (and classic ASP for that matter) there are a number of
intrinsic/built-in object provided globally by the environment itself.
Included in these objects is Response (the object that can send data
back to the client), Request (the object that contains the data sent
from the client to the server), Application (an object that can store
globally available data), and Session (an object that can store user
specific data). There are others but these will get you started. You
do not need to create these objects, you simply need to refer to them in
your code.

Now in your case you are reading and writing everything to the database,
so my original notes may not apply in your situation, you'll have to
decide that. However if you do decide to try and follow what I said
before you should know a couple of things.

First Application is created when the web application first starts up
and is available until the web application shuts down. You can catch
events that tell you when these happen in the Global.asax file(s).
You'll want to look into this because if you don't prepare your code for
it data may disappear during long periods of user inactivity and you may
want to reload it when the application reloads. The Application object
can be accessed by any of the connections/threads that are currently
active on the server. This means that you need to lock the access to the
Application object when modifying its contents so you don't run into
threading problems; to do this use Application.Loc k() before you add
something to it and Application.Unl ock() after you are done with it. Any
page that works with the Application object will be using data that is
available to all users connected to the system.

Second, there is the Session object. By default session only lasts
twenty minutes from the last time a user accessed the system (the server
does not have any other way to know if the user is still connected other
than if they make a request). This time limitation can be controlled in
the web.config file for the site. Session is only valid for a single
user connected to the system, however be aware that if the user opens
two separate browsers each one will have its own session (unless one was
launched from another then they share the same session). Session uses a
cookie by default to track an unique id that is used to retrieve data
for the specific user that it is associated to. When you store object
instances in Session they are only stored for (and retrievable by) the
browser instance associated to the unique id. Session can be made to
not require cookies (but then it puts the unique id in the querystring
for the page). Also Session can be configured to store its data in
memory (InProc) in an out of process Service (StateServer) or in an
external database (SqlServer). This is controlled by your web.config
file for the website (as is the session timeout). If you choose to
store session anywhere besides InProc (the default) you will have to
makes sure any object that you store in it is serializable or the system
will throw an exception (it uses serialization to marshal the object
across the process boundary between the site and the storage repository).

Now that all being said. Whether you use Application or Session you
store instances of objects (or primitives if you want) using a
name/value methodology. For example if you have an instance of an User
object called myUser and you want to put it in session you would do
something like (C# code):

Session["TheUserObjectK ey"] = myUser;

To retrieve this you would do something like:

User myUser = (User) Session["TheUserObjectK ey"];

This would work the same for the Application though you'd want to do the
Lock/Unlock pattern that I mentioned before. Also note that because
Application and Session store the base Object type you have to cast your
object back to the appropriate type when retrieving them back out.

Ok, that ran a bit longer than I thought it would but it is the basics
of how these objects work. Now if you want to store objects for the
users, you will want to see if their Session has an instance of your
data object, if it doesn't you'd query it from the database then put it
in Session, if it does you'll want to retrieve it from session and
display the appropriate values. Obviously you'll have to deal with the
issues involved with updating these data objects (if that is necessary
for your circumstances) and also you must realize that because
Application and Session have timeouts you will have objects hanging out
in memory until they expire (and then until the GC collects the object)
but this is standard for ASP.Net applications.

Hopefully this is enough to get you started. See the help files and
MSDN online documentation for more information. If you are looking to
do enterprise development in ASP.Net I'd really recommend that you
pickup a good ASP.Net book (search this newsgroup I'm sure you'll find
plenty of recommendations ). Also there are some webcasts being done on
ASP.Net out on Microsoft's site that might give you some pointers. Hope
something here helps.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm kinda new to professional asp.net development, so could you just clarify
the application and session objects?
I've got a module that houses many functions that all retrieve information
about their specific table from the database, writing the information into a
'.vb' class file. In effect, i am taking a snapshot of the database at that
current moment and storing it to the class, amending it there and then
writing changes back to the database afterwards. If i understand you
correctly, that is application level, therefore every user's instance of the
application sees the same data, whereas on a session level, each user would
see their own instance. Is this correct? If so, do you have any pointers
about making class files per session, not per application? I'm hugely
confused! The reason i'm developing like this is because i'm migrating an old
VB6 app and web-enabling it using ASP.NET. The old version used classes and i
was expected to re-use as much as possible. I think i understand that the
inherent difference is that with the old app it was installed seperately on
each computer, whereas the ASP.NET version is just one copy, installed on the
web server.
Any help would be gratefully receieved :)

"John M Deal" wrote:
>If I'm understanding you correctly you are loading data for the user
>from the database then storing that data into application scope. The
>issue that you then have is that you retrieve this data from application
>scope the next time the page is displayed. If this is the case then you
>should modify the way you are handling state management.
>
>The Application object should only be used to store data that is truly
>global to every user of the application. If you need to store things on
>a per user basis you should look into using the Session object. Using
>the Session object will allow you to store data classes on a per user
>basis.
>
>If you are worried about running the same query against the database
>multiple times, then you might want to abstract the use of the
>Application object (not a bad idea in general anyway) so that you can
>store a collection of query result sets keyed by the query used, then
>retrieve the appropriate result set for each user from the collection.
>If the collection doesn't contain the appropriate result set then you
>query the database and then add it to the collection and put the
>collection back in Application scope. Once you retrieve the appropriate
>result set from the application collection you could then put it in the
>user's Session object and continue your retrieval from there.
>
>Without more information on how you really intend to use these objects
>it is hard to know which solution to use, but hopefully something from
>the above will work for you.
>
>Have A Better One!
>
>John M Deal, MCP
>Necessity Software
>
>jsale wrote:
>
>>I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
>>i have made is running on IIS v6 and consists of a number of pages that allow
>>the user to read information from the database into classes, which are used
>>throughout the application. I have made class collections which, upon reading
>>from the DB, create an instance of the class and store the DB values in
>>there temporarily. My problem is that if user1 looks at record1, then user2
>>looks at record2, anything user1 does from that point onwards points the data
>>at record2.
>>Is there anything in particular i need to do to make the asp.net application
>>available to multiple users at the same time, each looking at different
>>records in the DB?
>>Thanks in advance
>

Nov 19 '05 #6
I guess I kind of got carried away, but it really didn't take as long as
you'd think.

Anyway in response to your question... yes each instance of the browser
is associated to one session object. If the user opens multiple
distinct instances of the browser they will get separate Session object
that their information is stored in, for each instance of the browser.
But for any given browser instance there is only one Session object and
it can be used by all the pages that the user navigates to on the same
website. Note that each ASP.Net website will have its own session
object so if you have two projects on the same server (each in their own
virtual directory) they will each have their own session objects
associated to the browser.

As for multiple users getting to the same Session objects it is
technically possible. This can happen if someone steals the cookie
while it is being transmitted, then uses it to spoof it to the server.
Also if you use cookieless session someone could type the unique id into
their URL and get to someone else's Session. Both of these take
intentional steps on behalf of the "hacker" but it is possible. Also
the session timeout helps with this in that if the user leaves their
browser open the cookie and/or url querystring are only good for 20
minutes (default); though if someone steals the cookie or querystring
they can resubmit to the site to keep the session alive for themselves.
Obviously you should do a threat analysis for this contingency to see if
you care to try and deal with these possibilities.

Hope that didn't confuse things.

John M Deal, MCP
Necessity Software

jsale wrote:
John, thanks so much for replying, I can't believe you're in work and sending
such long replies :)
That has helped a great deal, but one last thing, you said that session is
valid for only one user logged in, does that mean that each user can have
their own session, and each session can only be viewed by the one user?
Thanks again :)

"John M Deal" wrote:

I really wish I had more time to get into this in depth, but I'm at work
right now so I'll have to keep this short and rely on your ability to
run with this info.

In ASP.Net (and classic ASP for that matter) there are a number of
intrinsic/built-in object provided globally by the environment itself.
Included in these objects is Response (the object that can send data
back to the client), Request (the object that contains the data sent
from the client to the server), Application (an object that can store
globally available data), and Session (an object that can store user
specific data). There are others but these will get you started. You
do not need to create these objects, you simply need to refer to them in
your code.

Now in your case you are reading and writing everything to the database,
so my original notes may not apply in your situation, you'll have to
decide that. However if you do decide to try and follow what I said
before you should know a couple of things.

First Application is created when the web application first starts up
and is available until the web application shuts down. You can catch
events that tell you when these happen in the Global.asax file(s).
You'll want to look into this because if you don't prepare your code for
it data may disappear during long periods of user inactivity and you may
want to reload it when the application reloads. The Application object
can be accessed by any of the connections/threads that are currently
active on the server. This means that you need to lock the access to the
Application object when modifying its contents so you don't run into
threading problems; to do this use Application.Loc k() before you add
something to it and Application.Unl ock() after you are done with it. Any
page that works with the Application object will be using data that is
available to all users connected to the system.

Second, there is the Session object. By default session only lasts
twenty minutes from the last time a user accessed the system (the server
does not have any other way to know if the user is still connected other
than if they make a request). This time limitation can be controlled in
the web.config file for the site. Session is only valid for a single
user connected to the system, however be aware that if the user opens
two separate browsers each one will have its own session (unless one was
launched from another then they share the same session). Session uses a
cookie by default to track an unique id that is used to retrieve data
for the specific user that it is associated to. When you store object
instances in Session they are only stored for (and retrievable by) the
browser instance associated to the unique id. Session can be made to
not require cookies (but then it puts the unique id in the querystring
for the page). Also Session can be configured to store its data in
memory (InProc) in an out of process Service (StateServer) or in an
external database (SqlServer). This is controlled by your web.config
file for the website (as is the session timeout). If you choose to
store session anywhere besides InProc (the default) you will have to
makes sure any object that you store in it is serializable or the system
will throw an exception (it uses serialization to marshal the object
across the process boundary between the site and the storage repository).

Now that all being said. Whether you use Application or Session you
store instances of objects (or primitives if you want) using a
name/value methodology. For example if you have an instance of an User
object called myUser and you want to put it in session you would do
something like (C# code):

Session["TheUserObjectK ey"] = myUser;

To retrieve this you would do something like:

User myUser = (User) Session["TheUserObjectK ey"];

This would work the same for the Application though you'd want to do the
Lock/Unlock pattern that I mentioned before. Also note that because
Application and Session store the base Object type you have to cast your
object back to the appropriate type when retrieving them back out.

Ok, that ran a bit longer than I thought it would but it is the basics
of how these objects work. Now if you want to store objects for the
users, you will want to see if their Session has an instance of your
data object, if it doesn't you'd query it from the database then put it
in Session, if it does you'll want to retrieve it from session and
display the appropriate values. Obviously you'll have to deal with the
issues involved with updating these data objects (if that is necessary
for your circumstances) and also you must realize that because
Application and Session have timeouts you will have objects hanging out
in memory until they expire (and then until the GC collects the object)
but this is standard for ASP.Net applications.

Hopefully this is enough to get you started. See the help files and
MSDN online documentation for more information. If you are looking to
do enterprise development in ASP.Net I'd really recommend that you
pickup a good ASP.Net book (search this newsgroup I'm sure you'll find
plenty of recommendations ). Also there are some webcasts being done on
ASP.Net out on Microsoft's site that might give you some pointers. Hope
something here helps.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
I'm kinda new to professional asp.net development, so could you just clarify
the application and session objects?
I've got a module that houses many functions that all retrieve information
about their specific table from the database, writing the information into a
'.vb' class file. In effect, i am taking a snapshot of the database at that
current moment and storing it to the class, amending it there and then
writing changes back to the database afterwards. If i understand you
correctly, that is application level, therefore every user's instance of the
applicatio n sees the same data, whereas on a session level, each user would
see their own instance. Is this correct? If so, do you have any pointers
about making class files per session, not per application? I'm hugely
confused! The reason i'm developing like this is because i'm migrating an old
VB6 app and web-enabling it using ASP.NET. The old version used classes and i
was expected to re-use as much as possible. I think i understand that the
inherent difference is that with the old app it was installed seperately on
each computer, whereas the ASP.NET version is just one copy, installed on the
web server.
Any help would be gratefully receieved :)

"John M Deal" wrote:

If I'm understanding you correctly you are loading data for the user

from the database then storing that data into application scope. The

issue that you then have is that you retrieve this data from application
scope the next time the page is displayed. If this is the case then you
should modify the way you are handling state management.

The Application object should only be used to store data that is truly
global to every user of the application. If you need to store things on
a per user basis you should look into using the Session object. Using
the Session object will allow you to store data classes on a per user
basis.

If you are worried about running the same query against the database
multiple times, then you might want to abstract the use of the
Applicati on object (not a bad idea in general anyway) so that you can
store a collection of query result sets keyed by the query used, then
retrieve the appropriate result set for each user from the collection.
If the collection doesn't contain the appropriate result set then you
query the database and then add it to the collection and put the
collectio n back in Application scope. Once you retrieve the appropriate
result set from the application collection you could then put it in the
user's Session object and continue your retrieval from there.

Without more information on how you really intend to use these objects
it is hard to know which solution to use, but hopefully something from
the above will work for you.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:
>I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
>i have made is running on IIS v6 and consists of a number of pages that allow
>the user to read information from the database into classes, which are used
>througho ut the application. I have made class collections which, upon reading

>from the DB, create an instance of the class and store the DB values in

>there temporarily. My problem is that if user1 looks at record1, then user2
>looks at record2, anything user1 does from that point onwards points the data
>at record2.
>Is there anything in particular i need to do to make the asp.net application
>availabl e to multiple users at the same time, each looking at different
>records in the DB?
>Thanks in advance

Nov 19 '05 #7
Sorry if I didn't make this clear. You can put either instance of
classes or primitive variables in Session/Application because they cast
both types down to the Object type that all items in .Net inherit from.
The best way to see this is to create a simple ASP.Net page and play
with this from a couple of browsers hitting the same website.

John M Deal, MCP
Necessity Software

jsale wrote:
Finally (soooo sorry for carrying on!) is there a way of adding whole classes
to session and reading out of them, or does each variable have to be at
session level?
Cheers again,
Max

"jsale" wrote:

John, thanks so much for replying, I can't believe you're in work and sending
such long replies :)
That has helped a great deal, but one last thing, you said that session is
valid for only one user logged in, does that mean that each user can have
their own session, and each session can only be viewed by the one user?
Thanks again :)

"John M Deal" wrote:

I really wish I had more time to get into this in depth, but I'm at work
right now so I'll have to keep this short and rely on your ability to
run with this info.

In ASP.Net (and classic ASP for that matter) there are a number of
intrinsic/built-in object provided globally by the environment itself.
Included in these objects is Response (the object that can send data
back to the client), Request (the object that contains the data sent
from the client to the server), Application (an object that can store
globally available data), and Session (an object that can store user
specific data). There are others but these will get you started. You
do not need to create these objects, you simply need to refer to them in
your code.

Now in your case you are reading and writing everything to the database,
so my original notes may not apply in your situation, you'll have to
decide that. However if you do decide to try and follow what I said
before you should know a couple of things.

First Application is created when the web application first starts up
and is available until the web application shuts down. You can catch
events that tell you when these happen in the Global.asax file(s).
You'll want to look into this because if you don't prepare your code for
it data may disappear during long periods of user inactivity and you may
want to reload it when the application reloads. The Application object
can be accessed by any of the connections/threads that are currently
active on the server. This means that you need to lock the access to the
Applicatio n object when modifying its contents so you don't run into
threading problems; to do this use Application.Loc k() before you add
something to it and Application.Unl ock() after you are done with it. Any
page that works with the Application object will be using data that is
available to all users connected to the system.

Second, there is the Session object. By default session only lasts
twenty minutes from the last time a user accessed the system (the server
does not have any other way to know if the user is still connected other
than if they make a request). This time limitation can be controlled in
the web.config file for the site. Session is only valid for a single
user connected to the system, however be aware that if the user opens
two separate browsers each one will have its own session (unless one was
launched from another then they share the same session). Session uses a
cookie by default to track an unique id that is used to retrieve data
for the specific user that it is associated to. When you store object
instances in Session they are only stored for (and retrievable by) the
browser instance associated to the unique id. Session can be made to
not require cookies (but then it puts the unique id in the querystring
for the page). Also Session can be configured to store its data in
memory (InProc) in an out of process Service (StateServer) or in an
external database (SqlServer). This is controlled by your web.config
file for the website (as is the session timeout). If you choose to
store session anywhere besides InProc (the default) you will have to
makes sure any object that you store in it is serializable or the system
will throw an exception (it uses serialization to marshal the object
across the process boundary between the site and the storage repository).

Now that all being said. Whether you use Application or Session you
store instances of objects (or primitives if you want) using a
name/value methodology. For example if you have an instance of an User
object called myUser and you want to put it in session you would do
something like (C# code):

Session["TheUserObjectK ey"] = myUser;

To retrieve this you would do something like:

User myUser = (User) Session["TheUserObjectK ey"];

This would work the same for the Application though you'd want to do the
Lock/Unlock pattern that I mentioned before. Also note that because
Applicatio n and Session store the base Object type you have to cast your
object back to the appropriate type when retrieving them back out.

Ok, that ran a bit longer than I thought it would but it is the basics
of how these objects work. Now if you want to store objects for the
users, you will want to see if their Session has an instance of your
data object, if it doesn't you'd query it from the database then put it
in Session, if it does you'll want to retrieve it from session and
display the appropriate values. Obviously you'll have to deal with the
issues involved with updating these data objects (if that is necessary
for your circumstances) and also you must realize that because
Applicatio n and Session have timeouts you will have objects hanging out
in memory until they expire (and then until the GC collects the object)
but this is standard for ASP.Net applications.

Hopefully this is enough to get you started. See the help files and
MSDN online documentation for more information. If you are looking to
do enterprise development in ASP.Net I'd really recommend that you
pickup a good ASP.Net book (search this newsgroup I'm sure you'll find
plenty of recommendations ). Also there are some webcasts being done on
ASP.Net out on Microsoft's site that might give you some pointers. Hope
something here helps.

Have A Better One!

John M Deal, MCP
Necessity Software

jsale wrote:

I'm kinda new to professional asp.net development, so could you just clarify
the application and session objects?
I've got a module that houses many functions that all retrieve information
about their specific table from the database, writing the information into a
'.vb' class file. In effect, i am taking a snapshot of the database at that
current moment and storing it to the class, amending it there and then
writing changes back to the database afterwards. If i understand you
correctly , that is application level, therefore every user's instance of the
applicati on sees the same data, whereas on a session level, each user would
see their own instance. Is this correct? If so, do you have any pointers
about making class files per session, not per application? I'm hugely
confused! The reason i'm developing like this is because i'm migrating an old
VB6 app and web-enabling it using ASP.NET. The old version used classes and i
was expected to re-use as much as possible. I think i understand that the
inherent difference is that with the old app it was installed seperately on
each computer, whereas the ASP.NET version is just one copy, installed on the
web server.
Any help would be gratefully receieved :)

"John M Deal" wrote:

>If I'm understanding you correctly you are loading data for the user

>from the database then storing that data into application scope. The

>issue that you then have is that you retrieve this data from application
>scope the next time the page is displayed. If this is the case then you
>should modify the way you are handling state management.
>
>The Application object should only be used to store data that is truly
>global to every user of the application. If you need to store things on
>a per user basis you should look into using the Session object. Using
>the Session object will allow you to store data classes on a per user
>basis.
>
>If you are worried about running the same query against the database
>multiple times, then you might want to abstract the use of the
>Applicatio n object (not a bad idea in general anyway) so that you can
>store a collection of query result sets keyed by the query used, then
>retrieve the appropriate result set for each user from the collection.
>If the collection doesn't contain the appropriate result set then you
>query the database and then add it to the collection and put the
>collecti on back in Application scope. Once you retrieve the appropriate
>result set from the application collection you could then put it in the
>user's Session object and continue your retrieval from there.
>
>Without more information on how you really intend to use these objects
>it is hard to know which solution to use, but hopefully something from
>the above will work for you.
>
>Have A Better One!
>
>John M Deal, MCP
>Necessit y Software
>
>jsale wrote:
>
>
>>I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
>>i have made is running on IIS v6 and consists of a number of pages that allow
>>the user to read information from the database into classes, which are used
>>throughou t the application. I have made class collections which, upon reading
>
>>from the DB, create an instance of the class and store the DB values in
>
>>there temporarily. My problem is that if user1 looks at record1, then user2
>>looks at record2, anything user1 does from that point onwards points the data
>>at record2.
>>Is there anything in particular i need to do to make the asp.net application
>>availab le to multiple users at the same time, each looking at different
>>records in the DB?
>>Thanks in advance
>

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1330
by: Rÿffffe9veillÿffffe9 | last post by:
Hello, I have just started doing the python tutorials and i tried to modify one of the exercises, it has to to with defining functions. I wanted the user to be able to enter an option and then get a print of the selected option. I also wanted to have an exit for the user.
4
7016
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
3
5246
by: C# | last post by:
I have a richtextbox that i am copying to an invisible richtextbox . during the keydown and keypress events i am inserting HTML tags into the invisble richtextbox along with the origional text. The only problem i am running into is when the user presses the backspace and delete key i have a hard time knowing how to erase the charater(s) desired from the invisible richtextbox because it contains additional text. Any help is GREATLY...
5
4228
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
7
1979
by: Bala | last post by:
Hi All, I am trying to download the file from network machine (under same domain). I am using below link page code to impersonate. http://www.netomatix.com/ImpersonateUser.aspx I can able to impersonate the user, when i try to download the file, its says "unknown user name and password". I given full permission to domain user. but the same time when i provied the user name and deails on webconfig
13
2366
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
12
3411
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. Very simple. I would like to create listviewitem's for display in a listview control. The listview items need to contain properties from Internet Explorer windows i've managed to collect into an arraylist.
0
3051
by: William LaMartin | last post by:
The results I get below are as expected except for the Date/Time information. This seems to be a bug in System.Net.WebRequestMethods.Ftp.ListDirectoryDetails. It is not allowing enough space for all the Date/Time information. Does anyone have a solution for this other than getting the list by another method? For this code:
8
15145
tdw
by: tdw | last post by:
Hi, I have searched for this answer to no avail. I've found some very similar questions, but no answers that seem to apply. Here's the deal: All reports work fine on my computer. My boss, however, can't get reports to print correctly from his. What is happening is that his page margins in the 'page setup' keep resetting to include over 7" on the right, thus only allowing a narrow sliver on the left side of the page to print, thus, in...
0
8840
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8730
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9131
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.