Context/Session/Cache/ViewState objects

M

Mike

Hi,

I have an ASP.NET solution in which I need to store some information, such as DB user and password. So far, I have used the Context object to share information between the various pages, but I after having read some material, I have had the impression that the Cache object is better, since my variables are used throughout the entire application. Is that correct? If not, what is the best method for storing application variable (used throughout the application)?

Thanks.
Mike
 
H

Hermit Dave

context by itself is cannot hold any values.. you need to store it either
cache or application or session
if the data is to be shared between users then Cache is the best place
Application object used to be the place to store application wide variables
but if its gets overloaded then the aspnet process is bounced.
This is where Cache object comes into picture.. it will release the unused
items (based on priority) to make space for new objects being added if it is
running out of space.

if the data is to be shared between pages but only specific to a user then
session object is the place

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)

Hi,

I have an ASP.NET solution in which I need to store some information, such
as DB user and password. So far, I have used the Context object to share
information between the various pages, but I after having read some
material, I have had the impression that the Cache object is better, since
my variables are used throughout the entire application. Is that correct? If
not, what is the best method for storing application variable (used
throughout the application)?

Thanks.
Mike
 
J

Jens Christian Mikkelsen

Mike said:
I have an ASP.NET solution in which I need to store some information, such
as DB user and password. So far, I have used the Context object to share
information between the various pages, but I after having read some
material, I have had the impression that the Cache object is better, since
my variables are used throughout the entire application. Is that correct? If
not, what is the best method for storing application variable (used
throughout the application)?

The best place to store application variables is the ASP.NET Application
object, e.g.

Application("pwd") = "secret"

/Jens
 
J

Jens Christian Mikkelsen

Hermit Dave said:
Application object is not the best place... but it can be used

Hi Dave,

I fully agree with your observations about memory usage from the earlier
post. Shared cached data should go to the Cache object, user session state
to the Session object. But in some cases, there is also a case for
application state which should go to the Application object. You just have
to be careful, because the application state does not go away unless you
explicitly remove it or shut down the AppDomain. For a DB connection string,
I would probably choose the Application object.

/Jens
 
H

Hermit Dave

Hello Jen
well for DB connection string i prefer a encrypted connection string in
web.config.
for application data.. the best example i could think of is a singleton or
say business object

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 
S

Scott Allen

context by itself is cannot hold any values.. you need to store it either
cache or application or session
if the data is to be shared between users then Cache is the best place

Correct, but the Context.Items property is useful to hold references
around for the lifetime of the current request.
 
H

Hermit Dave

absolutely.. but to get there you first need to be deep down inside asp.net
coding. he's just starting and for his current requirements i dont think he
needs control over current request lifetime.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top