如何在ashx页面获取Session值

来源:互联网 发布:夏普电视音频输出端口 编辑:程序博客网 时间:2024/06/12 18:57

在一般事务处理页面,如果直接使用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"]    //..............}
原创粉丝点击