Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Use HttpHandler to add something to session, then display the page.

Reply
Thread Tools

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

 
 
zlf
Guest
Posts: n/a
 
      09-23-2007
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      09-23-2007
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
>



 
Reply With Quote
 
 
 
 
zlf
Guest
Posts: n/a
 
      09-23-2007
So it is impossible to add some logic before showing page using HttpHandler?
Thanks

"Teemu Keiski" <> 写入消息新闻:%233wVK1a$ bl...
> 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
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      09-23-2007
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$HHA.4476@TK2MSF TNGP06.phx.gbl...
> > 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
> >>

> >
> >

>
>
>

 
Reply With Quote
 
zlf
Guest
Posts: n/a
 
      09-24-2007
Let's take a example, if we set <add verb="*" path="*.aspx"
type="CustomHandler,HandlerAssembly"/>, at do
context.Response.Redirect(context.Request.Url.Abso lutePath) 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]" <> 写入消息新闻:EAD73C68-839F-40AE-A55C-...
> 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$ x.gbl...
>> > 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
>> >>
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
zlf
Guest
Posts: n/a
 
      09-24-2007
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$ l...
> Let's take a example, if we set <add verb="*" path="*.aspx"
> type="CustomHandler,HandlerAssembly"/>, at do
> context.Response.Redirect(context.Request.Url.Abso lutePath) 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]" <> 写入消息新闻:EAD73C68-839F-40AE-A55C-...
>> 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$ x.gbl...
>>> > 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
>>> >>
>>> >
>>> >
>>>
>>>
>>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display a Web Form then Do Something Larry Rebich ASP .Net Web Controls 1 10-21-2007 10:38 AM
Display a picture for say 5 seconds and then display a message. Mufasa ASP .Net 6 07-26-2007 11:09 PM
VS2005 "Add Web Reference" "Unable to connect to the remote server", then successfully displays the service info. Add reference button is disabled. Connecting to WS outside of VS is fast. BobC ASP .Net Web Services 1 01-25-2007 02:27 PM
When I open laptop lid i have display then it goes away then comes back Ed Computer Support 1 03-02-2006 07:26 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM



Advertisments