473,385 Members | 1,333 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,385 software developers and data experts.

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

Similar topics

8
by: Dave Wurtz | last post by:
All, I'm new to ASP development and I have a basic design question: Is it ok to store business objects to session variables or is there a better way to keep object information? For example,...
4
by: Ralph Krausse | last post by:
ViewState = "Bill"; -- This statement will send that to the browser and hash it into the __VIEWSTATE hidden varible Application = "Bill"; -- This statement will keep this info on the server ...
3
by: MattC | last post by:
With respect to Peter Bromberg's article ( http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my viewstate info in the Session object rather than the cache (as it is per user...
3
by: Alex Nitulescu | last post by:
Sorry, I'm really confused - I'm only at the middle of my book and already I can count 4 methods to store values. Yes, I know that cookies can not store much, but what is the difference between...
13
by: Alexander Widera | last post by:
hi, who has seen the follow problem or could help please? i visit a page .... i read a sesssion-var . ... everythink works...... i visit the page again..... error ... the sessionvar is null .... i...
3
by: Dragon | last post by:
Session ViewState Cache Already There are Session and ViewState What is the use of Cache ?
2
by: LeAnne | last post by:
My question is to do with scalability and the location for storate of cache, session, viewstate and application data. Application - Data is stored in memory (in process) Session - Data is stored...
6
by: AAOMTim | last post by:
I have a large ViewState and I've heard I can save the ViewState in a sesison object. What are the advantages of doing so and how do I do it? I've been told that I am gettign DNS timeouts because...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.