System.Web.Caching.Cache and error on my page

by volkanuzun 6/4/2008 5:23:00 AM

I am working on this web site, that does a lot of database queries, so i decided to use some caching mechanism here.

I do have a static function which reads the database, create a collection out the result and returns it to the caller, below is the simple code :

private static List<WebSite> GetWebSites()
    {
        List<WebSite> WebSites = (List<WebSite>)Cache["WebSites"];
        if (WebSites == null)
        {
            DatabaseAccess db = new DatabaseAccess(ConfigurationManager.ConnectionStrings["CSUWebSitesConnectionString"].ConnectionString);
            WebSitesTB webSitesTB = new WebSitesTB(db);
            WebSites = webSitesTB.GetAllWebSites();
            Cache["WebSites"] = WebSites;
        }
     ......

but i got the error:  Error    39    An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.Cache.get'    D:\WORK PROJECTS\CSUSBWebSitesApp\WebSitesApp\Administration\WebSites.aspx.cs    43    49    D:\...\WebSitesApp\

Can you guess what the problem is ? 

The problem is: Cache is a property of the class Page, and i am trying to access a property of page class, from a static function ; however this is not possible. What you should do is, change Cache to HttpContext.Current.Cache

 

Tags:

About the author

Volkan Uzun




E-mail me Send mail

Twitter

Calendar

<<  June 2008  >>
MoTuWeThFrSaSu
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

View posts in large calendar

Flickr Badge

www.flickr.com
This is a Flickr badge showing public photos from volkanuzun. Make your own badge here.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in