C#:访问.ashx.cs中的缓存变量

时间:2009-07-16 10:50:01

标签: c# asp.net

如何在处理程序类中访问缓存对象?

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 个答案:

答案 0 :(得分:4)

context.Cache应该有效。要使用context.Session,您应该通过实现IRequiresSessionState标记接口将处理程序标记为需要会话状态。

答案 1 :(得分:3)

你应该可以使用context.Cache,如果没有,你总是可以使用HttpRuntime.Cache(这就是HttpContext.Cache内部使用的内容)