Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to share MasterPages across projects

Tags:

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.

like image 642
Shawn Miller Avatar asked Aug 27 '08 18:08

Shawn Miller


People also ask

Can we use master page in MVC?

In addition to supporting partial views, ASP.NET MVC also supports the ability to create "master page" templates that can be used to define the common layout and top-level html of a site.

How do you create a master page?

To create the master pageIn Solution Explorer, right-click the name of your Web site, and then click Add New Item. Under Visual Studio installed templates, click Master Page. In the Name box, type Master1. Select the Place code in separate file check box.

How do I add a master page to an existing web form?

Add the master page into our project. Right click Project->Add->New item (shown in the picture), After clicking on new item, Window will open, select Web Form->Web Forms Master Page (shown in the picture), After clicking the add button, master page 'site1.

What is equivalent of ASP NET Master pages in Razor view?

Layout is similar to the master page in ASP.NET Web Form. Similar to master page, the Layouts may contain CSS, jQuery files and multiple views. Layout can keep the user interface elements and theme consistency throughout the application.


2 Answers

I have trying to accomplish the same thing. I look into a couple of solutions but I think using a virtual directory is probably the best way to share master pages.

Here are a couple sources that you can look at.

The third bullets near the end the article tells you of possible ways you can share Masterpages also.

like image 79
JkenshinN Avatar answered Oct 16 '22 01:10

JkenshinN


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

like image 42
Thomas Wagner Avatar answered Oct 16 '22 03:10

Thomas Wagner