您的位置:首页 > 其它

ashx文件中使用session提示“未将对象引用设置到对象的实例”

2014-05-15 10:41 676 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.SessionState;
namespace friends {
/// <summary>
/// Handler 的摘要说明
/// </summary>
public class Handler : IHttpHandler, IRequiresSessionState {

public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/plain";

在使用一般处理程序时,会用session,但是在ashx文件中,默认时,无法向session创建新的键值,写了就会报错,就会提示:“未将对象引用设置到对象的实例”

那么,将此ashx文件类继承一个接口,如以下所示:

System.Web.SessionState.IReadOnlySessionState 为只读会话的接口 继承这个接口,只能读取session 但不能为session赋值
System.Web.SessionState.IRequiresSessionState 为可读可写的 继承这个接口,即可读取session的值,也可以对其赋值,所以在一般处理程序中,继承这个接口
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐