Use HttpHandler to add something to session, then display the page.

Discussion in 'ASP .Net' started by zlf, Sep 23, 2007.

  1. zlf

    zlf Guest

    Hello,
    I try to use a custom HttpHandler to add something to session, then display
    the original page.

    public void ProcessRequest(HttpContext context)
    {
    context.Session["test"] = "test";
    }

    But, a empty page is rendered with this HttpHandler, should I add some
    additional codes to ProcessRequest to make it display the page correctly.

    Thanks
     
    zlf, Sep 23, 2007
    #1
    1. Advertising

  2. zlf

    Teemu Keiski Guest

    Page itself is sample of existing Httphandler, so your code doesn't really
    do anything else that the code shows (Page's equivalent implementation
    contains dealing with page lifecycle etc etc, a ton of logic) Maybe you want
    to redirect to the correct page? With

    context.Server.Transfer("page.aspx");

    Anyways, if your intention is to add some logic to the http application
    lifecycle instead of replacing the original HttpHandler, you'd want to use
    an HTTP Module

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "zlf" <> wrote in message
    news:eOX90da$...
    > Hello,
    > I try to use a custom HttpHandler to add something to session, then
    > display the original page.
    >
    > public void ProcessRequest(HttpContext context)
    > {
    > context.Session["test"] = "test";
    > }
    >
    > But, a empty page is rendered with this HttpHandler, should I add some
    > additional codes to ProcessRequest to make it display the page correctly.
    >
    > Thanks
    >
     
    Teemu Keiski, Sep 23, 2007
    #2
    1. Advertising

  3. zlf

    zlf Guest

    So it is impossible to add some logic before showing page using HttpHandler?
    Thanks

    "Teemu Keiski" <> дÈëÏûÏ¢ÐÂÎÅ:%233wVK1a$...
    > Page itself is sample of existing Httphandler, so your code doesn't really
    > do anything else that the code shows (Page's equivalent implementation
    > contains dealing with page lifecycle etc etc, a ton of logic) Maybe you
    > want to redirect to the correct page? With
    >
    > context.Server.Transfer("page.aspx");
    >
    > Anyways, if your intention is to add some logic to the http application
    > lifecycle instead of replacing the original HttpHandler, you'd want to use
    > an HTTP Module
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    > "zlf" <> wrote in message
    > news:eOX90da$...
    >> Hello,
    >> I try to use a custom HttpHandler to add something to session, then
    >> display the original page.
    >>
    >> public void ProcessRequest(HttpContext context)
    >> {
    >> context.Session["test"] = "test";
    >> }
    >>
    >> But, a empty page is rendered with this HttpHandler, should I add some
    >> additional codes to ProcessRequest to make it display the page correctly.
    >>
    >> Thanks
    >>

    >
    >
     
    zlf, Sep 23, 2007
    #3
  4. Re: Use HttpHandler to add something to session, then display the

    An HttpHandler isn't a "page" - it's a lightweight request handler without
    all the baggage of the Page Class. You could redirect or do a Server.Transfer
    to an actual ASPX page after you do your "stuff" in the handler.
    -- Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "zlf" wrote:

    > So it is impossible to add some logic before showing page using HttpHandler?
    > Thanks
    >
    > "Teemu Keiski" <> ôÈëÃûâÃÂÎÅ:%233wVK1a$...
    > > Page itself is sample of existing Httphandler, so your code doesn't really
    > > do anything else that the code shows (Page's equivalent implementation
    > > contains dealing with page lifecycle etc etc, a ton of logic) Maybe you
    > > want to redirect to the correct page? With
    > >
    > > context.Server.Transfer("page.aspx");
    > >
    > > Anyways, if your intention is to add some logic to the http application
    > > lifecycle instead of replacing the original HttpHandler, you'd want to use
    > > an HTTP Module
    > >
    > > --
    > > Teemu Keiski
    > > AspInsider, ASP.NET MVP
    > > http://blogs.aspadvice.com/joteke
    > > http://teemukeiski.net
    > >
    > >
    > > "zlf" <> wrote in message
    > > news:eOX90da$...
    > >> Hello,
    > >> I try to use a custom HttpHandler to add something to session, then
    > >> display the original page.
    > >>
    > >> public void ProcessRequest(HttpContext context)
    > >> {
    > >> context.Session["test"] = "test";
    > >> }
    > >>
    > >> But, a empty page is rendered with this HttpHandler, should I add some
    > >> additional codes to ProcessRequest to make it display the page correctly.
    > >>
    > >> Thanks
    > >>

    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Sep 23, 2007
    #4
  5. zlf

    zlf Guest

    Re: Use HttpHandler to add something to session, then display the

    Let's take a example, if we set <add verb="*" path="*.aspx"
    type="CustomHandler,HandlerAssembly"/>, at do
    context.Response.Redirect(context.Request.Url.AbsolutePath) in
    ProcessRequest(HttpContext context). The context.Response.Redirect will be
    handled by CustomHandler again, so that will lead to a infinite loop. Do I
    make some mistake?

    Thanks

    "Peter Bromberg [C# MVP]" <> дÈëÏûÏ¢ÐÂÎÅ:...
    > An HttpHandler isn't a "page" - it's a lightweight request handler without
    > all the baggage of the Page Class. You could redirect or do a
    > Server.Transfer
    > to an actual ASPX page after you do your "stuff" in the handler.
    > -- Peter
    > Recursion: see Recursion
    > site: http://www.eggheadcafe.com
    > unBlog: http://petesbloggerama.blogspot.com
    > BlogMetaFinder: http://www.blogmetafinder.com
    >
    >
    >
    > "zlf" wrote:
    >
    >> So it is impossible to add some logic before showing page using
    >> HttpHandler?
    >> Thanks
    >>
    >> "Teemu Keiski" <> D¡ä¨¨????¡éD???:%233wVK1a$...
    >> > Page itself is sample of existing Httphandler, so your code doesn't
    >> > really
    >> > do anything else that the code shows (Page's equivalent implementation
    >> > contains dealing with page lifecycle etc etc, a ton of logic) Maybe you
    >> > want to redirect to the correct page? With
    >> >
    >> > context.Server.Transfer("page.aspx");
    >> >
    >> > Anyways, if your intention is to add some logic to the http application
    >> > lifecycle instead of replacing the original HttpHandler, you'd want to
    >> > use
    >> > an HTTP Module
    >> >
    >> > --
    >> > Teemu Keiski
    >> > AspInsider, ASP.NET MVP
    >> > http://blogs.aspadvice.com/joteke
    >> > http://teemukeiski.net
    >> >
    >> >
    >> > "zlf" <> wrote in message
    >> > news:eOX90da$...
    >> >> Hello,
    >> >> I try to use a custom HttpHandler to add something to session, then
    >> >> display the original page.
    >> >>
    >> >> public void ProcessRequest(HttpContext context)
    >> >> {
    >> >> context.Session["test"] = "test";
    >> >> }
    >> >>
    >> >> But, a empty page is rendered with this HttpHandler, should I add some
    >> >> additional codes to ProcessRequest to make it display the page
    >> >> correctly.
    >> >>
    >> >> Thanks
    >> >>
    >> >
    >> >

    >>
    >>
    >>
     
    zlf, Sep 24, 2007
    #5
  6. zlf

    zlf Guest

    Re: Use HttpHandler to add something to session, then display the

    Resolved, do something like the following in ProcessRequest will be ok.
    Thanks

    string aspxPagePath = rawUrl.Substring(0,
    rawUrl.IndexOf(".aspx") + 5);
    IHttpHandler handler =
    PageParser.GetCompiledPageInstance(aspxPagePath, null, context);
    // Process the page just like any other aspx page
    handler.ProcessRequest(context);

    "zlf" <> дÈëÏûÏ¢ÐÂÎÅ:%23UP24El$...
    > Let's take a example, if we set <add verb="*" path="*.aspx"
    > type="CustomHandler,HandlerAssembly"/>, at do
    > context.Response.Redirect(context.Request.Url.AbsolutePath) in
    > ProcessRequest(HttpContext context). The context.Response.Redirect will be
    > handled by CustomHandler again, so that will lead to a infinite loop. Do I
    > make some mistake?
    >
    > Thanks
    >
    > "Peter Bromberg [C# MVP]" <> дÈëÏûÏ¢ÐÂÎÅ:...
    >> An HttpHandler isn't a "page" - it's a lightweight request handler
    >> without
    >> all the baggage of the Page Class. You could redirect or do a
    >> Server.Transfer
    >> to an actual ASPX page after you do your "stuff" in the handler.
    >> -- Peter
    >> Recursion: see Recursion
    >> site: http://www.eggheadcafe.com
    >> unBlog: http://petesbloggerama.blogspot.com
    >> BlogMetaFinder: http://www.blogmetafinder.com
    >>
    >>
    >>
    >> "zlf" wrote:
    >>
    >>> So it is impossible to add some logic before showing page using
    >>> HttpHandler?
    >>> Thanks
    >>>
    >>> "Teemu Keiski" <> D¡ä¨¨????¡éD???:%233wVK1a$...
    >>> > Page itself is sample of existing Httphandler, so your code doesn't
    >>> > really
    >>> > do anything else that the code shows (Page's equivalent implementation
    >>> > contains dealing with page lifecycle etc etc, a ton of logic) Maybe
    >>> > you
    >>> > want to redirect to the correct page? With
    >>> >
    >>> > context.Server.Transfer("page.aspx");
    >>> >
    >>> > Anyways, if your intention is to add some logic to the http
    >>> > application
    >>> > lifecycle instead of replacing the original HttpHandler, you'd want to
    >>> > use
    >>> > an HTTP Module
    >>> >
    >>> > --
    >>> > Teemu Keiski
    >>> > AspInsider, ASP.NET MVP
    >>> > http://blogs.aspadvice.com/joteke
    >>> > http://teemukeiski.net
    >>> >
    >>> >
    >>> > "zlf" <> wrote in message
    >>> > news:eOX90da$...
    >>> >> Hello,
    >>> >> I try to use a custom HttpHandler to add something to session, then
    >>> >> display the original page.
    >>> >>
    >>> >> public void ProcessRequest(HttpContext context)
    >>> >> {
    >>> >> context.Session["test"] = "test";
    >>> >> }
    >>> >>
    >>> >> But, a empty page is rendered with this HttpHandler, should I add
    >>> >> some
    >>> >> additional codes to ProcessRequest to make it display the page
    >>> >> correctly.
    >>> >>
    >>> >> Thanks
    >>> >>
    >>> >
    >>> >
    >>>
    >>>
    >>>

    >
    >
     
    zlf, Sep 24, 2007
    #6
    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. zootius
    Replies:
    0
    Views:
    814
    zootius
    Dec 7, 2005
  2. Mufasa
    Replies:
    6
    Views:
    897
    Scott M.
    Jul 27, 2007
  3. Larry Rebich

    Display a Web Form then Do Something

    Larry Rebich, Oct 16, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    113
  4. Replies:
    0
    Views:
    313
  5. Mel
    Replies:
    0
    Views:
    82
Loading...

Share This Page