想要在HttpHandler(ashx文件)中访问Session的状态值时,需要显式的实现一个接口 IReadOnlySessionState,示例如下:

 

<% @ webhandler language="C#" class="DownloadHandler" %> 
using System; 
using System.Web; 
using 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"]); 
  } 

 

如果要读写Session的值,那么只要实现 IRequiresSessionState 接口就可以了,这两个接口没有待实现的方法,可直接使用。

相关文章:

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