好记性不如烂笔头。

如何在ashx文件中使用Session

导入命名空间:

using System.Web.SessionState;

实现IRequiresSessionState接口

using System;
using System.Web;
using System.Web.SessionState;

public class Test : IHttpHandler,IRequiresSessionState{

    public void ProcessRequest (HttpContext context) {
        context.Session["Key"] = "Value";
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}