Ian*_*oyd 47 asp.net session session-state handler ihttphandler
我正在尝试一些值存储在会话从处理程序页面,我做一个重定向到一个页面的WebForms,这将拿起之前会话值和预填的WebForm:
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
...
context.Session["StackOverflow"] = "overflowing";
context.Response.Redirect("~/AnotherPage.aspx");
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
除了context.Session
object是null.
如何从处理程序访问会话状态?
Jos*_*rke 107
实现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");
}
}
Run Code Online (Sandbox Code Playgroud)
实现iRequiresSessionState是否解决了这个问题?
那么改为使用IHttpModule并覆盖BeginRequest呢?
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(context_BeginRequest);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
41146 次 |
最近记录: |