tags:

views:

182

answers:

2

How can one access cache objects in handler class?

public void ProcessRequest (HttpContext context) {
    //Cache["asd"] = "asd";
    //context.Response["1"]="sfd";
    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello World");
    string ss=(string)context.Cache["aasd"];
    string sss=(string)context.Session["sdf"];
}
+2  A: 

context.Cache should work. To use context.Session you should mark the handler to require session state by implementing the IRequiresSessionState marker interface.

Mehrdad Afshari
+1  A: 

You should be able to use context.Cache, if not you can always use HttpRuntime.Cache (which is what HttpContext.Cache uses internally anyway)

JonoW