master page in assembly

Topics: User Forum
Oct 27, 2006 at 12:10 AM
I've been trying to pick up ASP.NET and found your WAPL project particularly interesting. I want my pages in a web application to use a master page that's in an assembly being referenced by the web application. I can't seem to get that to work. It's complaining about the MasterPageFile...since that file lives in an assembly. Any ideas how to get around this? Thank you for your time!
Oct 30, 2006 at 1:52 PM
Hi Fritz,

Thats not something I've considered doing before. How are you associating the library master page with applications page?

Oct 30, 2006 at 3:57 PM
Hi Graham, thanks for the reply. I'm trying to build a framework assembly that I can drop into multiple applications. The framework comes with several built-in pages (such as an About page) and all of these built-in pages use a master page which is also in the assembly. This is the scenario you address in your WAPL example…which is great by the way!

My master page is called BasicLayout.master. When I drop the framework into my application, I want to be able to use BasicLayout.master for any application pages as well. I’m not sure I like this solution yet, but I ended up introducing a layer in the class hierarchy as follows:

BasicLayoutPage (hardcodes MasterPageClassName to BasicLayout)

The application page (.aspx) doesn’t refer to the master page in any way now, and instead the class in the code-behind file (.aspx.cs) inherits from the BasicLayoutPage class where the MasterPageClassName is hard-coded to BasicLayout. This seems to be working well. I don’t get the nice intellisense help to show me which content place holders are available, etc., but this is acceptable to me.

So with all of this working, I added a second level of master pages. For example, I created a ListMaintLayout.master that extends the BasicLayout.master. I’m just kind of hacking along at this point, but I’ve added the following to my class hierarchy.

BasicLayoutPage (hardcodes MasterPageClassName to BasicLayout)
ListMaintLayoutPage (hardcodes MasterPageClassName to ListMaintLayout)

And now, because a master page can have its own master page class name, I also added the following to my class hierarchy.

PrecompiledMasterPage (added a MasterPageClassName property)
BasicLayoutMasterPage (MasterPageClassName is blank)
ListMaintLayoutMasterPage (hardcoded MasterPageClassName to BasicLayout)

At this point, I’m still trying to get this to work. By the way, I’ve read on a different thread somewhere that they were able to serve up a master page from an assembly using a VirtualPathProvider, but I haven’t given this a shot yet. I don’t know if it would work with the precompiled pages or not. Still experimenting…
Oct 30, 2006 at 4:45 PM
Hey, I was able to get the nested master pages to work after all. I was referring to the master page's contentTemplates instead of its contentTemplateCollection. A lot of cleanup and refactoring (not to mention testing) to do. :)

Oct 30, 2006 at 4:57 PM
Using VirtualPathProvider's can be very benificial as they fit more closely with the assumptions Microsoft made when they designed MasterPages and UserControls. However, they don't handle multiple assemblies and browser caching as well as using a WebResource style method of serving.

The current impliementation of WAPL doesn't include support for master pages having their own master page. Just something I never got round to doing.
Oct 30, 2006 at 5:12 PM
Glad its working out for you, was starting to think no one else had found it useful :o)
Oct 30, 2006 at 5:22 PM
I was reading quite a bit about how you could deploy pages in assemblies, but yours was the only one that took it as far as you did. Like I said in my original post, I'm really new to .Net. I learned a lot from stepping through your code, so a big thanks to you for that!
Jul 29, 2007 at 4:30 AM
Hi Fritz,
I am trying to do the same exact thing, have a seperate masterpage assembly that contains the masterpage files to be used my reference in other applications. the problem I am having is the actual file does not exist in the virtual path and therefore give me an error because it cannot find the masterpage file. Did you ever get this done and if so can you please let me know how you did it.