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;
- }
- }
- }