Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing Cache from Custom Web Server Control

Reply
Thread Tools

Accessing Cache from Custom Web Server Control

 
 
Jordan S.
Guest
Posts: n/a
 
      05-30-2008
In a "standard" aspx page I can access the system cache
(System.Web.Caching.Cache), like this:
Cache["SomeObject"] = someObject;

How can I access the same Cache from *within* a custom composite Web server
control I'm writing (that lives in it's own assembly) that is dynamically
added to a page at runtime? What do I need to do with the custom control or
it's containing assembly to enable it to access the Cache of the hosting Web
application?

Thanks.




 
Reply With Quote
 
 
 
 
Peter Bucher [MVP]
Guest
Posts: n/a
 
      05-31-2008
Hello Jordan S.

> How can I access the same Cache from *within* a custom composite Web
> server control I'm writing (that lives in it's own assembly) that is
> dynamically added to a page at runtime? What do I need to do with the
> custom control or it's containing assembly to enable it to access the
> Cache of the hosting Web application?

Two Ways:

HttpContext.Current.Cache

this.Page.Cache

both gives the same Reference to the current Cache Object.

--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

 
Reply With Quote
 
 
 
 
Jordan S.
Guest
Posts: n/a
 
      05-31-2008
"Peter Bucher [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Jordan S.
>
>> How can I access the same Cache from *within* a custom composite Web
>> server control I'm writing (that lives in it's own assembly) that is
>> dynamically added to a page at runtime? What do I need to do with the
>> custom control or it's containing assembly to enable it to access the
>> Cache of the hosting Web application?

> Two Ways:
>
> HttpContext.Current.Cache
>
> this.Page.Cache
>
> both gives the same Reference to the current Cache Object.




Unfortunately neither of your suggestions works in my case. I want to access
the Cache from *within* a web server control. There is no "this.Page"
reference in a web server control.

The suggestion for HttpContext.Current.Cache seems promising, but it's
currently not available in my control's class.

Am I just missing some reference? The project/assembly within which my
control exists references System.Web. What else do I need to reference - or
what do I need to do to be able to access teh current context from within a
custom control?

Thanks.




 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      05-31-2008

Your just missing a reference. HttpContext.Current.Cache is the same
object. You can also use HttpRuntime.Cache. Little less overhead when
using this one.

I believe they are in System.Web
-joe

On May 30, 8:28*pm, "Jordan S." <(E-Mail Removed)> wrote:
> "Peter Bucher [MVP]" <(E-Mail Removed)> wrote in messagenews:(E-Mail Removed). ..
>
> > Hello Jordan S.

>
> >> How can I access the same Cache from *within* a custom composite Web
> >> server control I'm writing (that lives in it's own assembly) that is
> >> dynamically added to a page at runtime? What do I need to do with the
> >> custom control or it's containing assembly to enable it to access the
> >> Cache of the hosting Web application?

> > Two Ways:

>
> > HttpContext.Current.Cache

>
> > this.Page.Cache

>
> > both gives the same Reference to the current Cache Object.

>
> Unfortunately neither of your suggestions works in my case. I want to access
> the Cache from *within* a web server control. There is no "this.Page"
> reference in a web server control.
>
> The suggestion for HttpContext.Current.Cache seems promising, but it's
> currently not available in my control's class.
>
> Am I just missing some reference? The project/assembly within which my
> control exists references System.Web. What else do I need to reference - or
> what do I need to do to be able to access teh current context from within a
> custom control?
>
> Thanks.


 
Reply With Quote
 
Jordan S.
Guest
Posts: n/a
 
      05-31-2008
Got it... I was referencing System.Web... but was missing the using
statement.... (Doh!....)

Thanks.


"Joe" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

Your just missing a reference. HttpContext.Current.Cache is the same
object. You can also use HttpRuntime.Cache. Little less overhead when
using this one.

I believe they are in System.Web
-joe

On May 30, 8:28 pm, "Jordan S." <(E-Mail Removed)> wrote:
> "Peter Bucher [MVP]" <(E-Mail Removed)> wrote in
> messagenews:(E-Mail Removed). ..
>
> > Hello Jordan S.

>
> >> How can I access the same Cache from *within* a custom composite Web
> >> server control I'm writing (that lives in it's own assembly) that is
> >> dynamically added to a page at runtime? What do I need to do with the
> >> custom control or it's containing assembly to enable it to access the
> >> Cache of the hosting Web application?

> > Two Ways:

>
> > HttpContext.Current.Cache

>
> > this.Page.Cache

>
> > both gives the same Reference to the current Cache Object.

>
> Unfortunately neither of your suggestions works in my case. I want to
> access
> the Cache from *within* a web server control. There is no "this.Page"
> reference in a web server control.
>
> The suggestion for HttpContext.Current.Cache seems promising, but it's
> currently not available in my control's class.
>
> Am I just missing some reference? The project/assembly within which my
> control exists references System.Web. What else do I need to reference -
> or
> what do I need to do to be able to access teh current context from within
> a
> custom control?
>
> Thanks.





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
client-side cache vs server-side cache vs ajax vs asp.net callback =?Utf-8?B?b25l?= ASP .Net 1 03-08-2006 12:25 PM
Embed 3rd Party Server Control into my Custom Web Server Control Tim ASP .Net Web Controls 0 04-15-2005 03:13 PM
accessing the web user control's control from a web page and set a value from another web page Reny J Joseph Thuthikattu ASP .Net 1 12-30-2004 12:21 PM
View source while using Cache-Control: no-cache in frames Yaron Cohen Javascript 0 11-19-2003 10:06 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments