468,247 Members | 1,296 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Issue with HttpContext and HttpHandlers with Server.Transfer

Hello All,

I have an ASPX page whose class inherits from a company global base page.

The company base page has a property call PageTitle (string) that is
assigned by all the pages.
The base class also includes a class that is used for logging. This logging
class uses HttpContext.Current.Handler to get the instance of the page. In
this way, it can get the PageTitle property.

This works just fine with normal .ASPX pages, however, I also have an
HttpHandler that handles special URL's. This handler determines the page
that should handle the request, and then does a server.transfer to the
correct page.

The handler works, however, upon instantiation of the logging class of the
base page, it gets an error because the HttpContent.Current.Handler says
that it's the HttpHandler, and not the basepage.

Is there anyway I can get the instance of the Page's class, instead of the
Handler's class after using a HttpHandler and a Server.Transfer?

Thanks

Steve
Nov 19 '05 #1
3 1733
Hi Steve:

I'm a little confused -

You have a class derived from System.Web.UI.Page that serves as a base
class for all your pages. The base class includes the PageTitle
property and some logging code. Why does the class use
HttpContext.Current.Handler to get a reference to itself? Is the
method static / shared?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 20 Jun 2005 21:53:04 -0400, "Steve Lutz"
<sl***@nospam.comcast.net> wrote:
Hello All,

I have an ASPX page whose class inherits from a company global base page.

The company base page has a property call PageTitle (string) that is
assigned by all the pages.
The base class also includes a class that is used for logging. This logging
class uses HttpContext.Current.Handler to get the instance of the page. In
this way, it can get the PageTitle property.

This works just fine with normal .ASPX pages, however, I also have an
HttpHandler that handles special URL's. This handler determines the page
that should handle the request, and then does a server.transfer to the
correct page.

The handler works, however, upon instantiation of the logging class of the
base page, it gets an error because the HttpContent.Current.Handler says
that it's the HttpHandler, and not the basepage.

Is there anyway I can get the instance of the Page's class, instead of the
Handler's class after using a HttpHandler and a Server.Transfer?

Thanks

Steve


Nov 19 '05 #2
Hi Scott,

You were on the right track, but you fell off a little - sorry about the
poor explaination, here's a better one:

The Master baseclass contains a property called PageTitle. (We'll call this
class MasterPage)

There is another class called PageContext which is used to generate
Analyitic information. An instance of the PageContext class is created in
MasterPage's
contstructor. PageContext requires PageTitle from the masterPage to do it's
work. So to get this:

PageContext uses the current HttpContext to get the instance of the page
that it's on (HttpContext.Current.Handler) which is then cast into a
MasterPage, in order to get the PageTitle.

The problem is that with an HttpHandler, the HttpContext.Current.Handler is
not the MasterPage, even after a Server.Transfer to a page that does inherit
from MasterPage.

So the question is, is it possible to get the instance of the actual page
that is currently executing? I know it exists, because an instance
PageContext exists and that is created by the MasterPage.

I do have some-workaround changes (like sticking PageContext into an
HttpContext.Item, or creating an HttpHandler factory instead of using a
true HttpHandler).

Thanks for looking at this for me.

Steve

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:1v********************************@4ax.com...
Hi Steve:

I'm a little confused -

You have a class derived from System.Web.UI.Page that serves as a base
class for all your pages. The base class includes the PageTitle
property and some logging code. Why does the class use
HttpContext.Current.Handler to get a reference to itself? Is the
method static / shared?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 20 Jun 2005 21:53:04 -0400, "Steve Lutz"
<sl***@nospam.comcast.net> wrote:
Hello All,

I have an ASPX page whose class inherits from a company global base page.

The company base page has a property call PageTitle (string) that is
assigned by all the pages.
The base class also includes a class that is used for logging. This
logging
class uses HttpContext.Current.Handler to get the instance of the page. In
this way, it can get the PageTitle property.

This works just fine with normal .ASPX pages, however, I also have an
HttpHandler that handles special URL's. This handler determines the page
that should handle the request, and then does a server.transfer to the
correct page.

The handler works, however, upon instantiation of the logging class of the
base page, it gets an error because the HttpContent.Current.Handler says
that it's the HttpHandler, and not the basepage.

Is there anyway I can get the instance of the Page's class, instead of the
Handler's class after using a HttpHandler and a Server.Transfer?

Thanks

Steve

Nov 19 '05 #3
Oh! Makes sense now :)

I'm trying this out and do not see a way, offhand. In fact my Handler
property is null after the transfer, which is really odd. Are you
doing the Server.Transfer during the BeginRequest event handler for
your module? That's where mine is.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 21 Jun 2005 21:03:15 -0400, "Steve Lutz"
<sl***@nospam.comcast.net> wrote:
Hi Scott,

You were on the right track, but you fell off a little - sorry about the
poor explaination, here's a better one:

The Master baseclass contains a property called PageTitle. (We'll call this
class MasterPage)

There is another class called PageContext which is used to generate
Analyitic information. An instance of the PageContext class is created in
MasterPage's
contstructor. PageContext requires PageTitle from the masterPage to do it's
work. So to get this:

PageContext uses the current HttpContext to get the instance of the page
that it's on (HttpContext.Current.Handler) which is then cast into a
MasterPage, in order to get the PageTitle.

The problem is that with an HttpHandler, the HttpContext.Current.Handler is
not the MasterPage, even after a Server.Transfer to a page that does inherit
from MasterPage.

So the question is, is it possible to get the instance of the actual page
that is currently executing? I know it exists, because an instance
PageContext exists and that is created by the MasterPage.

I do have some-workaround changes (like sticking PageContext into an
HttpContext.Item, or creating an HttpHandler factory instead of using a
true HttpHandler).

Thanks for looking at this for me.

Steve

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:1v********************************@4ax.com.. .
Hi Steve:

I'm a little confused -

You have a class derived from System.Web.UI.Page that serves as a base
class for all your pages. The base class includes the PageTitle
property and some logging code. Why does the class use
HttpContext.Current.Handler to get a reference to itself? Is the
method static / shared?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 20 Jun 2005 21:53:04 -0400, "Steve Lutz"
<sl***@nospam.comcast.net> wrote:
Hello All,

I have an ASPX page whose class inherits from a company global base page.

The company base page has a property call PageTitle (string) that is
assigned by all the pages.
The base class also includes a class that is used for logging. This
logging
class uses HttpContext.Current.Handler to get the instance of the page. In
this way, it can get the PageTitle property.

This works just fine with normal .ASPX pages, however, I also have an
HttpHandler that handles special URL's. This handler determines the page
that should handle the request, and then does a server.transfer to the
correct page.

The handler works, however, upon instantiation of the logging class of the
base page, it gets an error because the HttpContent.Current.Handler says
that it's the HttpHandler, and not the basepage.

Is there anyway I can get the instance of the Page's class, instead of the
Handler's class after using a HttpHandler and a Server.Transfer?

Thanks

Steve


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Guadala Harry | last post: by
4 posts views Thread by Nicolas Beunier | last post: by
3 posts views Thread by Celebrate | last post: by
7 posts views Thread by Keith Patrick | last post: by
2 posts views Thread by =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post: by
1 post views Thread by mmorrison93 | last post: by
2 posts views Thread by Fernando Rodriguez | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.