一般的处理程序文件里面是用不了Session的,必须得实现Session接口才可以用。

 1  public class RandomCode : IHttpHandler, System.Web.SessionState.IRequiresSessionState //这里就是实现的接口
 2     {
 3         public void ProcessRequest(HttpContext context)
 4         {
 5             string checkCode = GetRandomCode(5);
 6             context.Session["CheckCode"] = checkCode;  //不实现接口 这个Session对象就是空的,会报未将对象引用到实例!
 7             SetPageNoCache();
 8             CreateImage(checkCode);
 9         }
10 }

 

相关文章:

  • 2021-09-14
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-10-18
相关资源
相似解决方案