Travis Collins
Travis Collins

Reputation: 4020

How to store an ASP.NET master page in a common library?

We would like to have several internal web applications which use the same master page. Is there a way to store a master page in a common library referenced by all projects?

Upvotes: 4

Views: 5327

Answers (4)

Samardeep
Samardeep

Reputation:

Hope this helps Sharing master page across the application

Enjoy.. :)

Upvotes: 0

baretta
baretta

Reputation: 7595

Given that these modules are part of the same web application, you should look at this approach:

Basically, you have one root web, which is set up as the(only) IIS web application. You may plug in new web modules by creating ASP.NET Web Application projects and place under the root web, physically. Set the build directory to root web's bin, eg. "..\bin". Don't create a IIS application/virtual directory.

Thereby, each web module compiles into its own DLL, which is itself a good thing. When compiling, it is "merged" with the root web.

It is a great way for sharing master pages and user controls, and have different parts of the web site in different projects/assemblies. Master pages and user controls will even work in design mode.

Upvotes: 0

Ben Scheirman
Ben Scheirman

Reputation: 40991

You can do this, but it is difficult and has quite a few drawbacks.

This process is similar to packaging up user controls as well. Basically you have a web application project that contains your master page. You can precompile this into a set of dlls using aspnet_compiler.

then you can use ilmerge.exe to put them all into a single dll that you then reference from your other projects.

You still need to have the markup in order for your pages to render properly in the designer, so you'll probably have to investigate VirtualPathProviders as well.

It's a kludgy solution and it has many drawbacks.

Upvotes: 2

thismat
thismat

Reputation: 2096

I've heard this works, I haven't tested it.

Create a separate project to house your master pages, since all master pages are like user controls and built into their own separate assembly. Run the build and try referencing the assembly of the master page.

Again, not tested, just something I've read before.

G'luck with it!

Upvotes: 0

Related Questions