ashx中默认不能使用session, HttpContext.Current.Session 为 null。

解决方法如下:

增加命名空间引用,实现指定接口

  1. <%@ WebHandler Language="C#" Class="Handler" %>   
  2.   
  3. using System;   
  4. using System.Web;   
  5. using System.Web.SessionState;   
  6.   
  7. public class Handler : IHttpHandler, IRequiresSessionState {   
  8.       
  9.     public void ProcessRequest (HttpContext context) {   
  10.          context.Response.ContentType = "text/plain";   
  11.          context.Response.Write("Hello World");   
  12.      }   
  13.   
  14.     public bool IsReusable {   
  15.         get {   
  16.             return false;   
  17.          }   
  18.      }   
  19.   
  20. }  

 

相关文章:

  • 2021-11-26
  • 2021-12-14
  • 2022-12-23
  • 2022-01-06
  • 2021-12-28
  • 2021-09-15
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-02-23
  • 2021-10-26
  • 2021-10-10
  • 2021-09-17
  • 2021-07-12
  • 2022-12-23
相关资源
相似解决方案