Scoping of components

N

No One

Is there any mechanism in an ASP.Net application to scope components? I
know that forms and the like are set to a request scoping and that is
fine, but there are certain components I need to have a global scope and
some a session scope.
 
N

No One

Are you saying I have to put the objects there? I cannot configure them to be
session scoped and have then created when a session starts?
 
K

Kevin Spencer

Hi Girish,
Are you saying I have to put the objects there? I cannot configure them to be
session scoped and have then created when a session starts?

When we're talking about scope, we're talking about memory (for the most
part - Session data can also be stored in a database, but must be
serializable in order to do so). Every Application has memory. In this case,
we're talking about a web server application, which is the memory space used
by ASP.Net for each web application defined in IIS. The application memory
space is where everything in the application's memory is stored. This
includes Application State, which is a Collection, Application Cache, which
is another Collection, and Session State, which is another Collection. Note
that all of these exist in the same "scope" which is the application memory
space of the app, which is global to the application. Session is not a
scope, but a Collection. Therefore, you can add and remove objects from the
Collection, but you can certainly not define them as having "Session Scope."

So, you could certainly create an instance of a class and store it in
Session when the Session starts, by using the global Session_OnStart event
handler.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
K

Kevin Spencer

One thing I should add, as Session is rather tricky: You could certainly
talk and think about an object being scoped to "Session Scope" as Sessions
are compartmentalized, and are indeed not visible to each other. While the
Session object is kept in Application memory (or in a database), it is
compartmentalized into separate Collections, one per client Session. This
makes Session scope a little confusing, and I'm not sure I've explained it
well enough.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top