469,363 Members | 2,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,363 developers. It's quick & easy.

Context/Session/Cache/ViewState objects


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


Nov 18 '05 #1
7 4297
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)
"Mike" <no****@nospam.com> wrote in message
news:eh**************@TK2MSFTNGP12.phx.gbl...

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

Nov 18 '05 #2
"Mike" <no****@nospam.com> skrev i en meddelelse
news:eh**************@TK2MSFTNGP12.phx.gbl...
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
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk
Nov 18 '05 #3
Application object is not the best place... but it can be used

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Jens Christian Mikkelsen" <je*********@jcmikkelsenNoSpamPlease.dk> wrote in
message news:u4**************@tk2msftngp13.phx.gbl...
"Mike" <no****@nospam.com> skrev i en meddelelse
news:eh**************@TK2MSFTNGP12.phx.gbl...
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
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk

Nov 18 '05 #4
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> skrev i en
meddelelse news:%2****************@TK2MSFTNGP09.phx.gbl...
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
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk
Nov 18 '05 #5
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)
"Jens Christian Mikkelsen" <je*********@jcmikkelsenNoSpamPlease.dk> wrote in
message news:#l**************@TK2MSFTNGP15.phx.gbl...
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> skrev i en
meddelelse news:%2****************@TK2MSFTNGP09.phx.gbl...
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
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk

Nov 18 '05 #6
On Sun, 29 Aug 2004 10:34:30 +0100, "Hermit Dave"
<he************@CAPS.AND.DOTS.hotmail.com> wrote:
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.

--
Scott
http://www.OdeToCode.com
Nov 18 '05 #7
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)
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:7d********************************@4ax.com...
On Sun, 29 Aug 2004 10:34:30 +0100, "Hermit Dave"
<he************@CAPS.AND.DOTS.hotmail.com> wrote:
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.

--
Scott
http://www.OdeToCode.com

Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Dave Wurtz | last post: by
4 posts views Thread by Ralph Krausse | last post: by
3 posts views Thread by MattC | last post: by
3 posts views Thread by Alex Nitulescu | last post: by
13 posts views Thread by Alexander Widera | last post: by
3 posts views Thread by Dragon | last post: by
2 posts views Thread by LeAnne | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.