IHttpModule, Context.Session == null?

Discussion in 'ASP .Net' started by oliver.wulff@zurich.ch, Jan 20, 2004.

  1. Guest

    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
    , Jan 20, 2004
    #1
    1. Advertising

  2. Teemu Keiski Guest

    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.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    <> wrote in message
    news:400d3b52$-datacenter.com...
    > 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
    Teemu Keiski, Jan 22, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger Stavcode
    Replies:
    0
    Views:
    417
    Roger Stavcode
    Jan 11, 2004
  2. Replies:
    5
    Views:
    26,476
    Mike Schilling
    Mar 29, 2006
  3. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    context.Session is null

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Jul 16, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    19,649
    navyjax2
    May 1, 2010
  4. asd
    Replies:
    1
    Views:
    422
    www.pulpjava.com
    Nov 9, 2006
  5. TMK
    Replies:
    0
    Views:
    352
Loading...

Share This Page