468,290 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

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

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
Sep 23 '07 #1
5 4089
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" <zl***@hotmail.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
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

Sep 23 '07 #2
zlf
So it is impossible to add some logic before showing page using HttpHandler?
Thanks

"Teemu Keiski" <jo****@aspalliance.com写入消息新闻:%2************ ****@TK2MSFTNGP06.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" <zl***@hotmail.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
>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


Sep 23 '07 #3
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" <jo****@aspalliance.com脨麓脠毛脧没脧垄脨脗脦脜:%2 ****************@TK2MSFTNGP06.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" <zl***@hotmail.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
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


Sep 23 '07 #4
zlf
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]" <pb*******@yahoo.yohohhoandabottleofrum.com写入消 ⑿挛:EA**********************************@microso ft.com...
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" <jo****@aspalliance.comD′è????¢D???:%2********* *******@TK2MSFTNGP06.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" <zl***@hotmail.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
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



Sep 24 '07 #5
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" <zl***@hotmail.com写入消息新闻:%2***************@T K2MSFTNGP06.phx.gbl...
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]" <pb*******@yahoo.yohohhoandabottleofrum.com写入消 ⑿挛:EA**********************************@microso ft.com...
>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" <jo****@aspalliance.comD′è????¢D???:%2********* *******@TK2MSFTNGP06.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" <zl***@hotmail.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
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



Sep 24 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jed | last post: by
4 posts views Thread by Jeremy Lew | last post: by
5 posts views Thread by the4man | last post: by
7 posts views Thread by Ty | last post: by
3 posts views Thread by Joe Reiss | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.