ashx中默认不能使用session, HttpContext.Current.Session为null。
解决方法如下:
实现接口System.Web.SessionState.IRequiresSessionState即可,代码如下:
using System;
using System.Web;
public class BoundaryHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState{
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello world");
}
public bool IsReusable {
get {
return false;
}
}
}
本文介绍了解决ASHX中默认无法使用Session的问题。通过实现IRequiresSessionState接口,可以使ASHX支持Session状态,示例代码展示了具体实现过程。
892





