Issue with HttpContext and HttpHandlers with Server.Transfer

S

Steve Lutz

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
 
S

Scott Allen

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?
 
S

Steve Lutz

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
 
S

Scott Allen

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.
 
Joined
Jul 6, 2009
Messages
1
Reaction score
0
Solution

For anybody who might read this, a good solution is to use

Code:
HttpContent.Current.[I]CurrentHandler[/I]

instead of

Code:
HttpContent.Current.[I]Handler[/I]

Steve Lutz said:
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
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top