Finding all Web Forms in a web site using reflection

Discussion in 'ASP .Net' started by Per Bolmstedt, Dec 14, 2006.

  1. (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/...
    Per Bolmstedt, Dec 14, 2006
    #1
    1. Advertising

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


    --

    Hope this helps,
    Mark Fitzpatrick
    Former Microsoft FrontPage MVP 199?-2006




    "Per Bolmstedt" <> wrote in message
    news:...
    > (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/...
    >
    Mark Fitzpatrick, Dec 14, 2006
    #2
    1. Advertising

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

    On Dec 14, 2:36 pm, "Mark Fitzpatrick" <> wrote:
    > 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 atwww.asp.netand see if there is a difference. I stopped using the web site
    > project for similar compilation issues.
    >
    > --
    >
    > Hope this helps,
    > Mark Fitzpatrick
    > Former Microsoft FrontPage MVP 199?-2006
    >
    > "Per Bolmstedt" <> wrote in messagenews:...
    >
    > > (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/...
    Per Bolmstedt, Dec 14, 2006
    #3
  4. Per Bolmstedt

    bruce barker Guest

    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)


    Per Bolmstedt wrote:
    > (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/...
    >
    bruce barker, Dec 14, 2006
    #4
  5. 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?

    On Dec 14, 5:21 pm, bruce barker <> wrote:
    > 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)
    >
    > Per Bolmstedt wrote:
    > > (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/...
    Per Bolmstedt, Dec 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z25hbmE=?=

    Finding Controls in a page using System.Reflection

    =?Utf-8?B?Z25hbmE=?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    463
    =?Utf-8?B?U3RldmVu?=
    Apr 4, 2006
  2. guava
    Replies:
    1
    Views:
    2,671
    Joseph Millar
    Aug 8, 2003
  3. Carfield Yim
    Replies:
    1
    Views:
    1,392
    Andrew Thompson
    May 31, 2004
  4. Julian
    Replies:
    3
    Views:
    4,508
    Thomas Schodt
    Apr 30, 2005
  5. ravi
    Replies:
    3
    Views:
    715
Loading...

Share This Page