ASP.NET : 핸들러에서 세션에 액세스하는 방법은 무엇입니까? [복제하다
-
21-08-2019 - |
문제
이 질문은 이미 여기에 답이 있습니다.
나는 몇 가지 값을 저장하려고합니다 세션 a 매니저 페이지, WebForms 페이지로 리디렉션하기 전에 세션 값 및 웹 폼을 미리 채우는 것 :
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
...
context.Session["StackOverflow"] = "overflowing";
context.Response.Redirect("~/AnotherPage.aspx");
...
}
...
}
제외하고 context.Session
객체는 null입니다.
핸들러에서 세션 상태에 액세스하려면 어떻게해야합니까?
해결책
구현 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");
}
}
다른 팁
구현하다 IRequiresSessionState
구현합니다 IREQUIRESSESSIONSTATE 이것을 해결 하시겠습니까?
대신 ihttpmodule을 수행하고 시작 레퀴스트를 우선적으로 수행하는 것은 어떻습니까?
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(context_BeginRequest);
}
제휴하지 않습니다 StackOverflow