.net - with - share master page between projects
What is the best way to share MasterPages across projects (6)
Are you trying to share MasterPages across multiple projects? If yes, take a look at this question.
If no, what are you trying to do?
Suppose you have two seperate ASP.NET Web Application projects that both need to use a common MasterPage.
What's the best way to share the MasterPage across projects without having to duplicate code? Preferably without having to resort to source control or file system hacks.
From K. Scott Allen's ASP.Net Master Pages: Tips, Tricks, and Traps article, on "Sharing Master Pages":
The first alternative is to copy shared master page files into a single location on an IIS web server. Each application can then create a virtual directory as a subdirectory and point the virtual directory to the real directory of master pages. The applications can then set the MasterPageFile property of a page to the name of the virtual directory, plus the name of the master page file. When we drop an updated master page file into the real directory, the new master page will appear in all the applications immediately.
A second approach is to use a version control system to share a set of master page files across multiple projects. Most source control / version control systems support some level of “share” functionality, where a file or folder can appear in more than one project. When a developer checks in an updated master page file, the other projects will see the change immediately (although this behavior is generally configurable). In production and test, each application would need to be redeployed for the update master page to appear.
Finally, the VirtualPathProvider in ASP.NET 2.0 can serve files that do not exist on the file system. With the VirtualPathProvider, a set of master pages could live in database tables that all applications use. For an excellent article on the VirutalPathProvider, see “Virtualizing Access to Content: Serving Your Web Site from a ZIP File”.
If you want all the files to be part of the same solution then it is very similar to the problem of Sharinging Master Pages across Projects
Checkout the links on that question and the following links:
- Sharing Master Pages in Visual Studio
- Sharing Master Pages Across IIS Applications
- Sharing Master Pages amongst Applications by Embedding it in a Dll
- Master Pages: Tips, Tricks, and Traps
- Serving Website from a Zip Files
- VirtualPathProvider In Precompiled Web Sites
If you're only concerned about sharing static files, not dynamic, then I'd suggest following Chris Lively's advise and host them on a separate domain. Customize your build process to copy the files when necessary.
Keep a primary copy in source control, and let your source control system worry about it.
How to specify physical path in ASPX page?
You cannot share a master page between applications this way. All paths within an asp.net app are relative.
The virtual path provider simply will not reach above the current apps root.
You will need to either write a custom virtual path provider, which is not trivial, or package the master pages in a shared assembly.
You will find guidance in this question: What is the best way to share MasterPages across projects
IIS7 & VS2010 Solution setup for multiple websites with shared assets (JS, CSS, images, etc.)
The best way is to have a site such as "static.mydomain.com" which hosts your javacript, images, and css. You'll typically have this site set up for some aggressive caching.
For web services, have a site called "services.mydomain.com" which hosts all of your web services.
All of the other sites go to their respective domains.
The main sites will reference all of their artifacts through something like
<img src='http://static.mydomain.com/images/myimage.jpg' />
The only real complexity here is with your automated builds. But even that isn't too hard depending on your build server.
Yes, this is a pretty common approach. Further by separating out those static artificats, it makes it easier to shift them to a CDN at a later date if you want.