在一般事务处理页面,如果直接使用Session获取值HttpContext.Current.Session[“CheckCode”]的话是会报 “未将对象引用设置到对象的实例”的异常
所以,如果要想取Session中的值 ,需要如下所示
1、引入 命名空间:
using System.Web.SessionState;
2、实现IRequiresSessionState接口,具体如下
using System;
using System.Web;
using System.Data;
using System.Text;
using System.Web.SessionState;
//实现IRequiresSessionState接口
public class getRandCode : IHttpHandler, IRequiresSessionState
{
var code= HttpContext.Current.Session["CheckCode"]
//..............
}