Archive for the ‘Microsoft .NET’ Category

XHTML compliance, .NET2 and validator.w3c.org

Friday, November 9th, 2007

Something to watch out for …

We had a minor “hiccup” on www.immediacy.net yesterday when we noticed that validator.w3c.org was reporting 2 XHTML 1.0 strict validation errors on the home page. We take XHTML compliance pretty seriously as it is one of the selling points of our content management system.

The built in Immediacy XHTML checker wasn’t reporting any problems and a visual inspection of the XHTML source code implied that validator.w3c.org was actually mistaken in reporting any errors.

We’ve recently switched the Immediacy.net site to running in .NET2 and I suspected this may be the cause of the problem.

A bit of investigation revealed that when validator.w3c.org requests pages from a site, it does so with a user_agent value of “W3C_Validator”.

.NET has the “ability” to automatically recognise what it considers to be “downlevel” browsers and re-render certain HTML controls differently to match the capabilities of the browser. The theory is that .NET can automatically downgrade a website to automatically support devices such as phones and pdas, however in practice I’m not sure how well this works.

.NET was determining that “W3C_Validator” was a downlevel browser and rendering different HTML to the validator than to human visitors of the site.

The solution is relatively straightforward. Simply paste the following configuation code into the “browsercaps” section of the web.config on your website. This will tell .NET to treat W3C_Validator as if it were a Mozilla browser.

<!– Gets .NET to treat validator.w3c.com as if it were Mozilla. Otherwise it tends to render invalid XHTML !!–>
<case match=”^W3C_Validator/”>
browser=Mozilla
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
version=6.0
majorversion=6
minorversion=0
</case>
<!– end W3C_Validator–>

XHTML 1.0 strict compliance restored