application cache

  • Thread starter Thread starter KaaN
  • Start date Start date
K

KaaN

hi,

in an asp.net application, i can not access the server-side
application data using,

cachedata = Application["data"];

when it is not a page behind class. can i use the cache in another
class of the application for example in myutils.cs which is not a page
behind class?
 
KaaN said:
hi,

in an asp.net application, i can not access the server-side
application data using,

cachedata = Application["data"];

when it is not a page behind class. can i use the cache in another
class of the application for example in myutils.cs which is not a page
behind class?

You can access Application in a codebehind file because it is a property
of the parent-class: Page.

Look into System.Web.HttpContext.Current, you might find it there.

Hans Kesting
 
First, when you reference Application["data"] you're not referencing the
Application Cache; you're referencing the Application Collection. Generally
speaking, you should be using the Application Cache, for which the syntax
would be Cache["data"]. The Application Collection is really there for
backwards compatibility and is not threadsafe.

To reference any HttpContext-specific object in a class which doesn't
inherit System.Web.UI.Control, you would refer to
System.Web.HttpContext.Current to accesss it. For example, to reference the
Application Cache "data" item, you would refer to
System.Web.UI.HttpContext.Current.Cache.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top