在ashx中使用Session

默认在ashx中是不能正常使用Session的(能存入不能取出),查阅相关文档,说明只有实现IRequiresSessionState接口后ashx才能正常使用Session,代码如下:

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Web.SessionState;//1.添加引用

public class Handler : IHttpHandler, IRequiresSessionState//2.继承接口
{
    
    public void ProcessRequest (HttpContext context) {
        
        context.Session["URL"] = "http://www.mzwu.com/";
        context.Response.Write(context.Session["URL"].ToString());
        
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}


评论: 0 | 引用: 0 | 查看次数: 3517
发表评论
登录后再发表评论!