项目中,调用 ashx 一般处理程序获取行政区划Json数据,在 ashx 里面有用到Session,但是总无法获取 Session 。

  查阅资料得知 ashx 一般处理程序要使用 Session,必须实现 Session 接口,如下:

using System.Web.SessionState;
public class RegionHandle : HttpHandler,IRequiresSessionState {
     
    public void ProcessRequest (HttpContext context) {
     ...
        //获取Session保存的用户名
        string currUserName = context.Session["UserName"].ToString();
     ...
  }
  
    public bool IsReusable {
        get {
            return false;
        }
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2021-09-14
  • 2022-03-01
相关资源
相似解决方案