ASP.NET:如何从处理程序访问会话?
问题描述:
我正在尝试在中存储一些值来自 Handler 页面的会话,在我重定向到 WebForms 页面之前,它将获取 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");
...
}
...
}
除了 context.Session
对象为空.
如何从处理程序访问会话状态?
How do i access Session state from a handler?
答
实施 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");
}
}