views:

47

answers:

3

Is there a way to share a master page between different MVC projects/applications?

We have several different applications, and would like those apps to share a similar header and footer on the web pages.

What is the best approach to handle this situation with ASP.NET MVC?

A: 

To accomplish this, wouldn't you also need to share CSS, Images, and scripts? Are you sharing them between solutions or projects?

It sounds like to answer this, you would also need to answer the question: How can I share files between 2 different solutions / projects. I think that answer is somewhat dependent on what kind of revision control system you are using.

MedicineMan
The CSS, images, and scripts is part of the problem as well. I have spent too many years working on classic ASP, where I would use shared folders for things like images and scripts and then have an includefile for the header and footer. But I am not sure of the clean way to do this with MVC. We are using subversion for source control of our .net projects.
Swoop
+1  A: 

I do not believe you can share master pages, but I have done something like this with MVC.

I have a website project and and administrative project, both MVC 2 applications. I have a master page for both projects. I then create a "ResourceURL" app setting in the web.config. From there I prefix all "resource" assets with that config entry. Now I store all my web files like CSS, scripts, images, etc int he website project and reference them from both projects.

This also works nicely to allow for a CDN integration down the line.

Dustin Laine
+1  A: 

Without some tricks, you can't do it. And as @MedicineMan mentions, the workarounds will depend somewhat on your source control system.

One way to deal with this is to add pre and/or post build steps to your project, which copy a version of the file into the other the projects. You'll need to include the master as a item in the project, and some version systems clients will want to include the copy of the file.

chris