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

Z

zlf

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
 
T

Teemu Keiski

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
 
Z

zlf

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

Teemu Keiski said:
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 said:
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
 
G

Guest

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 said:
So it is impossible to add some logic before showing page using HttpHandler?
Thanks

Teemu Keiski said:
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 said:
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
 
Z

zlf

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 said:
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 said:
So it is impossible to add some logic before showing page using
HttpHandler?
Thanks

Teemu Keiski said:
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


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
 
Z

zlf

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 said:
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 said:
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 said:
So it is impossible to add some logic before showing page using
HttpHandler?
Thanks

"Teemu Keiski" <[email protected]> D¡ä¨¨????¡éD???:%[email protected]...
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


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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top