有三点需要注意:

1.命名空间中要加入using System.Web.SessionState;

2.接口名要加入IRequiresSessionState或IReadOnlySessionState;

3.不管是Session还是QueryString都要通过HttpContext来获取。

具体代码如下:

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

using System;
using System.IO;
using System.Net;
using System.Web;
using System.Web.SessionState;

public class UploadHandler : IHttpHandler, IRequiresSessionState
{
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Charset = "utf-8";

        string str1 = context.Session["aaa"].ToString();
        string str2 = context.Request.QueryString["bbb"].ToString();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

相关文章:

  • 2021-07-12
  • 2021-09-15
  • 2022-01-06
  • 2021-10-10
  • 2021-12-28
  • 2021-09-14
  • 2022-01-19
  • 2022-12-23
猜你喜欢
  • 2021-09-17
  • 2022-12-23
  • 2021-10-26
  • 2022-02-23
  • 2021-10-16
  • 2021-11-26
相关资源
相似解决方案