Hi A.M,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you've create a custom attribute for a Page class
which is used to perform as the base class of the pages in your web
application. Since you want to do some operations based on this custom
attribute at the begining of a request, you're looking for some approachs
to attrieve the Page's class in a certain HttpModule so as to use the class
to retreive the custom attribute.
If there is anything I misunderstood, please feel free to let me know.
Based on my research, in ASP.NET runtime, we can retrieve the request's
related page class(IHttpHandler) just as bruce barker said, using the
"HttpContext.Current.Handler". By default, if you haven't specified a
certain custom HttpHandler for the certain type of request,
"HttpContext.Current.Handler" is just the requested page's class. However,
the problem now is when could we retrieve it.
Generaly the whole sequence a ASP.NET request is processed is called the
ASP.NET pipeline. Once the request makes it in to the worker process, it
goes throught a series of steps and classes before it arrives at the
ultimate handler(by default is a certain page class). The simple sequence
is :
HttpWorkerRequest created--------->HttpRuntime class create a new instance
of HttpContext class ------------>the HttpContext instance generate other
necessary instance such as HttpRequest, HttpResponse... ----------->The
ApplicationFactory create a certain HttpApplication instance and the
HttpApplication instance initialize itself--------------> The HttpModules
are created instances and serve the request---------------->
HttpHandlerFactory create the instance of the correct HttpHandler(the page
class) and the HttpHandler calls its "ProcessReqeust" Method. Once the
ProcessRequest method returns, the request is complete.
For detailed infos on the ASP.NET runtime pipeline, you can view the
following tech article in MSDN:
#The ASP.NET HTTP Runtime
http://msdn.microsoft.com/library/en-us/dnaspp/html/dngrfTheASPNETHTTPRuntim
e.asp?frame=true
So we could notice that the HttpHandler( the page class) is created at the
end of the pipeline. When the HttpModules instances are created, the
HttpHandler instance hasn't been created yet. So that means we can't
retrieve the Page class(HttpHandler) instance at that time.
Since the means using HttpModule fails, I've also tried retrieved the
HttpHandler in the Global object's Application events, such as
"Application_BeginRequest", "Application_EndRequest",
"Application_AuthenticateRequest" However, only in the
"Application_EndRequest" can I retrieve the page ( HttpHandler) instance
via the "HttpContext.Current.Handler", but I don't think the EndRequest is
the time you want.
So I haven't found a place other than the Page's event such as "Init" or
"Load" that could I got the HttpHandler instance so far. As you want to do
some modification based on the custom attribute of the page class, do you
think is possible to move the operation to other later event such as
"Page_Init" ? Or do you think we can look for any other means to workaround
this?
Please check out the preceding suggestions. If you have any questions or
need any help, please feel free to let me know.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)