ASP.NET:如何从处理程序访问会话?

发布于 2024-07-25 06:58:20 字数 579 浏览 4 评论 0原文

尝试在会话中存储一些值Handler 页面 中获取 Session 值并预填充 WebForm

public class Handler : IHttpHandler
{
   public void ProcessRequest(HttpContext context)
   {
      ...
      context.Session["StackOverflow"] = "overflowing";
      context.Response.Redirect("~/AnotherPage.aspx");
      ...
   }
   ...
 }

context.Session 对象为空。

如何从处理程序访问会话状态?

i'm trying to store some values in the Session from a Handler page, before i do a redirect to a WebForms page, that will pick up the Session values and pre-fill the WebForm:

public class Handler : IHttpHandler
{
   public void ProcessRequest(HttpContext context)
   {
      ...
      context.Session["StackOverflow"] = "overflowing";
      context.Response.Redirect("~/AnotherPage.aspx");
      ...
   }
   ...
 }

Except context.Session object is null.

How do i access Session state from a handler?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜声 2024-08-01 06:58:20

实现 System.Web.SessionState.IRequiresSessionState界面

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState 
{   
  public void ProcessRequest(HttpContext context)  
  {      
    context.Session["StackOverflow"] = "overflowing";      
    context.Response.Redirect("~/AnotherPage.aspx");      
  }

}

Implement the System.Web.SessionState.IRequiresSessionState interface

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState 
{   
  public void ProcessRequest(HttpContext context)  
  {      
    context.Session["StackOverflow"] = "overflowing";      
    context.Response.Redirect("~/AnotherPage.aspx");      
  }

}
柏林苍穹下 2024-08-01 06:58:20

实现IRequiresSessionState

Implement IRequiresSessionState

如何视而不见 2024-08-01 06:58:20

实施 iRequiresSessionState 是否可以解决此问题?

改为使用 IHttpModule 并重写 BeginRequest 怎么样?

    public void Init(HttpApplication application)
    {
        application.BeginRequest += new EventHandler(context_BeginRequest);
    }

Does implementing iRequiresSessionState resolve this?

What about doing an IHttpModule instead and overriding BeginRequest?

    public void Init(HttpApplication application)
    {
        application.BeginRequest += new EventHandler(context_BeginRequest);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文