On one web project there was a need to turn on and off the ability to print on individual pages. The print control is on the master page and the administrator wishes to be able to adjust which pages may print easily. The solution is actually simple:
- Add a new attribute to the Sitemap node, for illustration we will use a XmlSiteMap as shown below with @mapPrint:
- Add a static class and method to the application:
- In the master page, just read the value!
You will notice that I actually have not hard coded the attribute name. I have provided a default value which I may alter from web.config as needed. Items like this I would usually add to a Web Server Control Library so I can reuse the code everywhere.
This same pattern may be used for any other information that you wish to associate with specific pages. The mechanism is simple and can often eliminate a stack of spagetti coding (which may be hard-coded to make it worst).