W3C validation of ASP.Net output

A while ago I had to make certain that a CMS driven site built in .Net met some validation criteria.  Specifically the XHTML markup.  Running it by the W3C validator service, the markup always failed.

I fixed the obvious within the web.config.  For example, the following is needed to force the application to render XHTML:

		<xhtmlConformance mode="Strict" />

If I painfully cut and pasted the HTML into the Validator’s form field, it passed.  The problem is, is that the service is not recognised by the Web server, and so a helper file in the application is required.

In your web root, create a App_Browsers directory.  Within this directory create a file called w3c.browser.  Paste the following contents into the file:

	<browser id="W3C_Validator" parentID="default">
			<userAgent match="^W3C_Validator" />
			<capability name="browser" value="W3C Validator" />
			<capability name="ecmaScriptVersion" value="1.2" />
			<capability name="javascript" value="true" />
			<capability name="supportsCss" value="true" />
			<capability name="tables" value="true" />
			<capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" />
			<capability name="w3cdomversion" value="1.0" />

You should now be able to pass the page by URL:


Leave a Reply

Your email address will not be published.