木子屋 Dnawo's BLOG

在ashx中使用Session

👤 dnawo 📅 2009-06-04 👁 4314 👍 0 💬 0 🔄 本站原创
默认在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)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 Effective C# 原则9:明白几个相等运算之间的关系 下一篇 → N73上wap站提示:内容类型不被支持