Get ASPX page's class Type by its path.

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.
 
B

bruce barker

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.
|
|
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top