Enabling SessionState...

  • Thread starter Philipp Schumann
  • Start date
P

Philipp Schumann

....BUT for _custom_ HttpHandlers. How can I do that?

In my custom IHttpHandler, HttpContext.Current.Session is a null reference,
and I can't use the session state. It is enabled in web.config and
machine.config however, and normal aspx pages can use it just fine.

Here's the call stacks for a standard aspx and my custom http handler
showing how the code needed to enable the session state is missing. However
I don't know how I can make up for this. new SessionStateModule ().Init
(HttpContext.Current.ApplicationInstance) for example does NOT help here at
all.

Here's the stacks:

// First stack: When starting a session by requesting .aspx file:
IAM.Web.dll!IAM.Global.Session_Start(System.Object sender =
{System.Web.SessionState.SessionStateModule}, System.EventArgs e =
{System.EventArgs})

system.web.dll!System.Web.SessionState.SessionStateModule.RaiseOnStart(System.EventArgs
e = {System.EventArgs}) + 0xad Bytes

system.web.dll!System.Web.SessionState.SessionStateModule.OnStart(System.EventArgs
e = {System.EventArgs}) + 0x16 Bytes

system.web.dll!System.Web.SessionState.SessionStateModule.CompleteAcquireState()
+ 0x1be Bytes

system.web.dll!System.Web.SessionState.SessionStateModule.BeginAcquireState(System.Object
source = {ASP.Global_asax}, System.EventArgs e = {System.EventArgs},
System.AsyncCallback cb = {System.AsyncCallback}, System.Object extraData =
<Nicht definierter Wert>) + 0x31e Bytes

system.web.dll!AsyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+ 0x3e Bytes

system.web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep
step = {System.Web.HttpApplication.AsyncEventExecutionStep}, bool
completedSynchronously = true) + 0xd7 Bytes

system.web.dll!System.Web.HttpApplication.ResumeSteps(System.Exception
error = { }) + 0x149 Bytes

system.web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext
context = {System.Web.HttpContext}, System.AsyncCallback cb =
{System.AsyncCallback}, System.Object extraData = {System.Web.HttpContext})
+ 0xac Bytes

system.web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest
wr) + 0x1e7 Bytes

system.web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest
wr) + 0xb0 Bytes

system.web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(int ecb, int
iWRType) + 0x65 Bytes





// Second stack: When a session _should_ be started, but isn't, while
requesting a .custom file:
IAM.Web.dll!IAM.Web.HttpHandler.ProcessRequest(System.Web.HttpContext
context = {System.Web.HttpContext})

system.web.dll!CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+ 0xf9 Bytes

system.web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep
step = {System.Web.HttpApplication.CallHandlerExecutionStep}, bool
completedSynchronously = true) + 0x86 Bytes

system.web.dll!System.Web.HttpApplication.ResumeSteps(System.Exception
error = { }) + 0x149 Bytes

system.web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext
context = {System.Web.HttpContext}, System.AsyncCallback cb =
{System.AsyncCallback}, System.Object extraData = {System.Web.HttpContext})
+ 0xac Bytes

system.web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest
wr) + 0x1e7 Bytes

system.web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest
wr) + 0xb0 Bytes

system.web.dll!System.Web.Hosting.ISAPIRuntime.ProcessRequest(int ecb, int
iWRType) + 0x65 Bytes
 
S

Scott Allen

Hi Philipp:

You need to tell the runtime that you want session state by deriving
from one of the two "marker" interfaces: IRequiresSessionState or
IReadOnlySessionState.

These interfaces are marker interfaces because there are no methods
they force you to implement - they simply serve to decorate your
class. the Runtime can test to see if your handler derives from one of
these two interfaces and then put session state together accordingly.

HTH,
 
P

Philipp Schumann

Thanks, Scott!
Best,
Phil

Scott Allen said:
Hi Philipp:

You need to tell the runtime that you want session state by deriving
from one of the two "marker" interfaces: IRequiresSessionState or
IReadOnlySessionState.

These interfaces are marker interfaces because there are no methods
they force you to implement - they simply serve to decorate your
class. the Runtime can test to see if your handler derives from one of
these two interfaces and then put session state together accordingly.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top