Get ASPX page's class Type by its path.

  • Thread starter Thread starter Oleg Ogurok
  • Start date Start date
O

Oleg Ogurok

Hi all,

Given a virtual path (URL) to a page, I need to programmatically get its
class type.
For example, there is a page /MyAspNetApp/TargetPage.aspx.
I need to get the automatically generated class to check its type, e.g. to
check if the class implements a certain interface. The base class
(codebehind) will do as well.

I see there is a System.Web.UI.PageParser.GetCompiledInstance() method but
unfortunatelly I can't use it in my scenario. Basically I don't want to
create an instance, just get the compiled type.

There is also, System.Web.UI.PageParser.GetCompiledType(), which looks like
exactly what I need, but this method is marked as internal.

Is there anything I could do?

Thanks,
-Oleg.
 
the problem you will have is until the page has been compiled, the
information does not exists. when a page is hit, it will be compiled and the
dll placed in a temp dir. at this point the page dll is loaded into the
current appdomain, and you could use reflection to find it (though the name
gets munged), unless it gets recompiled, in which case you will find two
copies.

if you have good naming convetion, you can load the codebehind assembly and
use reflection to fint the code-behind class, then check for the interface.
if code needing to the lookup is in the codebehind then its really simple.

-- bruce (sqlwork.com)


| Hi all,
|
| Given a virtual path (URL) to a page, I need to programmatically get its
| class type.
| For example, there is a page /MyAspNetApp/TargetPage.aspx.
| I need to get the automatically generated class to check its type, e.g. to
| check if the class implements a certain interface. The base class
| (codebehind) will do as well.
|
| I see there is a System.Web.UI.PageParser.GetCompiledInstance() method but
| unfortunatelly I can't use it in my scenario. Basically I don't want to
| create an instance, just get the compiled type.
|
| There is also, System.Web.UI.PageParser.GetCompiledType(), which looks
like
| exactly what I need, but this method is marked as internal.
|
| Is there anything I could do?
|
| Thanks,
| -Oleg.
|
|
 
Back
Top