Events in HttpModule

Discussion in 'ASP .Net' started by nerd, Apr 30, 2004.

  1. nerd

    nerd Guest

    Hi,

    I've easily implemented an HttpModule and use AcquireRequestState to
    initialize an object and ReleaseRequestState store to session. Unfortunately
    if a Response.Redirect takes place. The ReleaseRequestState does not fire.
    No problem, I implement PreSendRequestContent or PreSendRequestHeaders and
    now I'm able to fire the event before the Response.Redirect. But Uhoh, I've
    got no access to the Session or Context.Items objects???

    Please help I'm stumped on when/where to fire an event and still have access
    to session and context before firing response.redirect.

    Thanks,
    John Haynes

    jhaynes "at" mckinleycapital "dot" com
    nerd, Apr 30, 2004
    #1
    1. Advertising

  2. nerd

    Natty Gur Guest

    Hi,

    the source parameter holds HttpApplication so you can get context from
    it :

    public void Init(HttpApplication application)
    {
    application.BeginRequest += (new
    EventHandler(this.Application_BeginRequest));
    application.EndRequest += (new
    EventHandler(this.Application_EndRequest));
    application.PreSendRequestContent += (new EventHandler(this.App));
    }

    private void App(Object source, EventArgs e)
    {
    HttpApplication application = (HttpApplication)source;
    HttpContext context = application.Context;
    }

    anyway you can also use EndRequest.

    HTH

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, May 2, 2004
    #2
    1. Advertising

  3. nerd

    John Haynes Guest

    Getting to the context or session is not the problem, the problem is they no
    longer exist at that point in the HttpPipeline they've already been dumped
    from the HttpContext...

    They are null nothing do not exists at this point. In debug mode when ">?
    HttpContext", Current, Session and a few other elements have already been
    dumped. As simple as it may seem I have no access to those elements at that
    point. At runtime it produces object not found errors

    I'd like to find some actual documentation that details what happens when
    the events in the pipeline get bypassed. For example. I was using
    ReleaseRequestState but Response.Redirect never fires ReleaseRequestState
    and goes right to the next page. Where AcquireRequesState will fire. On a
    full page load I can run ReleaseRequestState and have full access to Context
    and Session but the peculiar thing is PreSendRequestContent and
    PreSendRequestHeader preceed ReleaseRequestState in the HttpPipeline yet I
    dont have access to the Context or Session there. I have been unable to find
    documentation that supports this.

    Thanks for the info though.

    John

    "Natty Gur" <> wrote in message
    news:...
    > Hi,
    >
    > the source parameter holds HttpApplication so you can get context from
    > it :
    >
    > public void Init(HttpApplication application)
    > {
    > application.BeginRequest += (new
    > EventHandler(this.Application_BeginRequest));
    > application.EndRequest += (new
    > EventHandler(this.Application_EndRequest));
    > application.PreSendRequestContent += (new EventHandler(this.App));
    > }
    >
    > private void App(Object source, EventArgs e)
    > {
    > HttpApplication application = (HttpApplication)source;
    > HttpContext context = application.Context;
    > }
    >
    > anyway you can also use EndRequest.
    >
    > HTH
    >
    > Natty Gur[MVP]
    >
    > blog : http://weblogs.asp.net/ngur
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    John Haynes, May 2, 2004
    #3
    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. shiv
    Replies:
    0
    Views:
    467
  2. Alvin Bruney
    Replies:
    1
    Views:
    713
  3. Holly Li

    HttpModule events

    Holly Li, Aug 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,300
    Holly
    Aug 4, 2004
  4. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    555
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    341
    Chris
    Aug 30, 2005
Loading...

Share This Page