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;
}
}
本文转自 彭金华 51CTO博客,原文链接:http://blog.51cto.com/pengjh/595853