IHttpModule, Context.Session == null?

O

oliver.wulff

Hi
I wrote a IHttpModule which should store an object in the session.
Unfortunately, the session is empty:
public void OnAuthenticateRequest(object o, EventArgs ea)
{
HttpApplication httpApp = (HttpApplication) o;
HttpSessionState session = httpApp.Context.Session;

If I set the WebMethod attribute 'EnableSession' of my webservice
(HttpModule is active either) I can access the session in the web service
method implementation but not in the HttpModule.
What am I doing wrong?

Oliver
 
T

Teemu Keiski

Hi,

You have code tied to the request authentication phase, right? At that phase
session is not available yet as it becomes availabe when
OnAcquireRequestState is called. See following article for the sequence of
HttpApplication events.

http://www.eggheadcafe.com/articles/20030211.asp

There you can see that AuthenticateRequest happens long before
OnAcquireRequestState. Also note that if HttpHandler implements
IRequiresSessionState or IreadOnlySessionState or not at all, has also
impact if Session is available (therefore OnAcquireRequestState is called
after creating the HTTP handler instance so that it is known does the
session need to be accessible or not). Of course with web service and
EnableSession=true it is there by the HTTP handler, but doesn't remove the
fact that it is not available until OnAcquireRequestState is called.
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top