Obtaining class namespace from absolute url request string

  • Thread starter Thread starter Pete
  • Start date Start date
P

Pete

Hi,

I am writing a pre-handler page for aspx pages, in which I
want to call a custom method on the code-behind class file
for the aspx page.

In order to do this I need to somehow get the class full
namespace for the codebehind aspx page from the request
absolute url that I have in the pre-handler page.

The question is how do I obtain the class namespace string
so I can use reflection on the webserver dll file to load
this dynamically. At present I am using a lookup table
that maps the absolute url to the namespace class, and
then using the assembly.gettype() and then creating an
instance of the class from using the type.

I am sure there must be some method available that doesn't
require maintainence of this list?? - as the default pre-
handler passes the absolute url request to the aspx page
by default anyway. Any ideas?


Thanks.


Pete.
 
Pete said:
Hi,

I am writing a pre-handler page for aspx pages, in which I
want to call a custom method on the code-behind class file
for the aspx page.

In order to do this I need to somehow get the class full
namespace for the codebehind aspx page from the request
absolute url that I have in the pre-handler page.

Can you read the .aspx file? If so, you can read the @Page directive, which
should include a Inherits attribute which should tell you the full name of
the class. I believe that should be enough to load the class and create an
instance of it so that you can call a method.
 
John,

When you say read, are you meaning reading the file at
runtime, and parsing this information out from the file?

Does the default .Net pre-page handler use this technique
to get the code behind class to instantiate for the page?,
surely not?? Or if so, is there some function that I can
call to get the code-behind class for the aspx page?


Thanks.


Pete.
 
Pete said:
John,

When you say read, are you meaning reading the file at
runtime, and parsing this information out from the file?

Yes, I meant reading the file and parsing the information. There's not that
much of it, after all.
Does the default .Net pre-page handler use this technique
to get the code behind class to instantiate for the page?,
surely not?? Or if so, is there some function that I can
call to get the code-behind class for the aspx page?

Why? What would be wrong with that technique? Especially if you cache the
result?

I don't know if this is what ASP.NET uses.
--
John Saunders
Internet Engineer
(e-mail address removed)

 
Caching sounds good but it would be nice if someone from
Microsoft could give an indication as to how ASP.Net does
it internally. Maybe the information is already known in
a property of a object model that is accessible from the
pre-page handler, perhaps??


Pete.
 
Back
Top