A reminder to myself and others, when you want to get access to your Session State from an ASHX or HttpHandler, you need to implement IReadOnlySessionState:
提醒自己和其他人,当您想从ASHX或HttpHandler访问会话状态时,需要实现IReadOnlySessionState:
<% @ webhandler language="C#" class="DownloadHandler" %>
<%@ webhandler language =“ C#” class =“ DownloadHandler”%>
using System;
using System.Web;
using System.Web.SessionState;使用系统; 使用System.Web; 使用System.Web.SessionState;
public class DownloadHandler : IHttpHandler, IReadOnlySessionState{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write(ctx.Session["fred"]);
}
}公共类DownloadHandler:IHttpHandler, IReadOnlySessionState { 公共布尔IsReusable {get {return true; }} 公共无效ProcessRequest(HttpContext ctx) { ctx.Response.Write(ctx.Session [“ fred”]); } }
翻译自: https://www.hanselman.com/blog/getting-session-state-in-httphandlers-ashx-files