Finding all Web Forms in a web site using reflection

P

Per Bolmstedt

(This question has been asked previously in this group, but I don't
think it was ever really properly answered.)

I want to use reflection - preferably - to find all Web Forms in my web
site that inherit my base page class (which in turn inherits
System.Web.UI.Page). Behold the following code:

For Each asm As System.Reflection.Assembly In
System.AppDomain.CurrentDomain.GetAssemblies()
For Each mdl As System.Reflection.Module In asm.GetModules()
For Each typ As System.Type In mdl.GetTypes()
If typ.IsSubclassOf(GetType(MyBasePage))
..

This code only seems to list Web Forms that have actually been run. Why
is that? Even pages within the same assembly don't show up until they
have been run. Also, this behaviour is the same in the ASP.NET
Development Server and a web site published with the ASP.NET compiler
running in IIS.

Is there another, better, way to find a list of all Web Forms in a web
site?

I want to avoid having to inspect all DLL files in ~/bin/...
 
M

Mark Fitzpatrick

Are you using the typical ASP.Net Web Site project, or are you using the
add-on Web Application project. I don't think the Web Site project forms are
truly getting pre-compiled in the same fashion that the Web Application
project or the old VS 2003 web projects did. You might experiment by
creating an app with the new web application project download over at
www.asp.net and see if there is a difference. I stopped using the web site
project for similar compilation issues.
 
P

Per Bolmstedt

It's a normal "ASP.NET Web Site" created with VS2005.

I don't think precompilation is the issue since the behaviour exhibits
on a "published" web site as well.

The merge tool in the WAP template would probably let me reflect the
way I want, but I'd still be interested in explanations of the
behaviour, as well as possible solutions for an ASP.NET Web Site...
 
B

bruce barker

reflection can only see loaded assemblies. in asp.net each page is a
seperate dll (though using batching can cause some grouping). each page
dll gets loaded the first time its referenced. if the site is not
precompiled, the dll don't even exist until the page is requested
(always true in version 1).

in 1.1 the code-behinds were compiled into one dll (by vs), so
reflection could see the base classes for web pages, but the actual page
class was not available until the actual page dll was loaded.


-- bruce (sqlwork.com)
 
P

Per Bolmstedt

I'm using ASP.NET 2.0 and the ASP.NET Web Site template, so none of
this applies. Rather, each ASP.NET directory gets compiled into its own
App_Web_????????.dll assembly. But "pages" (classes that inherit a
class that inherits System.Web.UI.Page) in the same assembly don't show
up in the sample reflection code below unless they're explicitly
invoked, which I find odd.

But I guess the WAP template is the only real solution. Can anyone
verify that it does indeed solve my problem?
 

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
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top