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

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
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

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"?>
        <pages masterPageFile="~/fruit.master" />
    <location path="apples">
            <pages masterPageFile="~/apple.master" />
    <location path="oranges">
            <pages masterPageFile="~/orange.master" />

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:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



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