ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Protecting your server from a crashing application
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Apply Master Pages By Folder

Everyone who's used ASP.NET master pages knows that you can specify which master page a content page should use via the content page's Page directive. Most people also know that you can also set it either programatically via code or via the Web.config file. But did you know you can also set it by folder?

This can come in quite handy when your site is organized by content type. For example, if you keep all your apple-related products in the /apples folder and all your orange-related products in the /oranges folder, you might want to create a style for each that complements the folder's content.

Continuing the above example, take a look at this short sample Web.config file.

<?xml version="1.0"?>
<configuration>
    <system.web>
        <pages masterPageFile="~/fruit.master" />
    </system.web>
    <location path="apples">
        <system.web>
            <pages masterPageFile="~/apple.master" />
        </system.web>
    </location>
    <location path="oranges">
        <system.web>
            <pages masterPageFile="~/orange.master" />
        </system.web>
    </location>
</configuration>

The first section specifies that the pages in this Web should use the fruit.master file. After that, we create two location elements, one for the /apples folder and another for the /oranges folder. Under each of those, we specify which master page file should be used by Web forms in those folders. The net result of these settings is that pages in the /apples folder will use apple.master, pages in the /oranges folder will use orange.master, and all other pages in the Web will use fruit.master.

You can override these settings by specifying a master page at the page level, but otherwise, ASP.NET will follow the settings in the Web.config file to determine which master page to use for every Web form that includes an <asp:Content> control.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers