.NET 追寻足迹

C# 之路

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

 

posted on 2010-12-31 17:19  绿水青山  阅读(347)  评论(0编辑  收藏  举报