Two months ago I started working on a new project for the Dutch government, the site must comply with all the standards specified by this government (http://webrichtlijnen.overheid.nl/). One of the guidelines is to use xhtml-strict and stylesheets for the markup for their sites. So we started building this according to all the specified standards. We delivered the project as planned, to my surprise the test results told us that the site was not build according by the xhtml-standard.
To validate all the pages I use Firefox
with the web developer plug-in. When I was finished to validate all pages I couldn’t reproduce the malfunction, all my pages were xhtml-strict. I was a bit confused, but after a bit of mind bending I could reproduce the error. I validated my local html rendered by my Firefox client (Ctrl+Shift+A) instead of the html that was rendered by the W3C-client. Now that I found the problem I could start focusing on the solution.
When .NET renders it’s code for a client, it uses browsercaps to determine the compatibility mode for the client. If the client, that requests a rendering of html, is not recognized by .NET it tries to render html that is compatible for ancient browsers. By altering your browsercaps it is possible to make the W3C-client available and make it an up-level browser. But nowadays nobody actually uses low-level browsers. We want to use xhtml so that all browsers can interpret our mark-up code. So we need to level-up all the browsers and render very well formed xhtml for all the browsers. If you are familiar with browsercaps you probably know what to do now. But for the people who don’t know I have written a small how to.
How to up-level all the clients with browsercaps*
If you open your web.config you have a section browsercaps or you can create one. In this section you normally specify a lot of different browsers and their capabilities. But what if all the browsers should render the same mark-up. Just paste the following xml in your web.config and all off the browsers render the same mark-up code in xhtml strict.
<system.web>
<xhtmlConformance mode="Strict" />
<browserCaps>
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
</browserCaps>
</system.web>
*this applies to .NET 2.0 applications