Getting W3C to validate XHTML Strict ASP.NET Pages

Visual Studio (2005 and 2008) by default generates XHTML Transitional code, but can be configured to generate Strict code. However, the W3C validator does not identify itself as a Strict enabled browser and so online validation will fail. This mini-tutorial shows how to get your application to pass W3C's automated test.

The problem

Whenever IIS delivers an ASP.NET page it uses the information in the request to determine ther browsers capabilities. If IIS cannot determine the  browser it defaults it to a 'down-level' capability and delivers legacy code. The biggest symptom of this is that it uses the 'name' attribute in tags instead of 'id'. Since W3C identifies itself as a 'peculiar' browser, it receives down-level' code and so it fails any pages it is asked to validate.

The solution - getting started

You dotNET application should at least be configured with the correct DOCTYPE.

<!DOCTYPE html PUBLIC 
   "-//W3C//DTD XHTML 1.0 Strict//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

This can be done in the MasterPage for your application.

Also, to force the dotNET runtime to generate XHTML strict compliant code you must make sure you have the following entry in the <system.web> section of your web.config file:

<xhtmlConformance mode="Strict"/>

The final piece of the jigsaw

We now need to make sure that IIS can identify W3C's requests as being from a XHTML Strict capable source.

This is done by providing a browser identification file in a special ASP.NET folder called App_Browsers.

  • Use 'Add ASP.NET folder' to add the App_Browsers folder to the root of your application.
  • Add a new Browser file to the folder and replace its default dummy content with the following:
<!--
  Browser capability file for the w3c validator
  sample UA: "W3C_Validator/1.305.2.148 libwww-perl/5.803" -->
<browsers>
 <browser id="w3cValidator" parentID="default">
  <identification>
   <userAgent 
    match="^W3C_Validator" />
  </identification>
  <capture>
   <userAgent
      match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" />
  </capture>
  <capabilities>
   <capability name="browser" value="w3cValidator" />
   <capability name="majorversion" value="${major}" />
   <capability name="minorversion" value="${minor}" />
   <capability name="version" value="${version}" />
   <capability name="w3cdomversion" value="1.0" />
   <capability name="xml" value="true" />
   <capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" />
  </capabilities>
 </browser>
</browsers>

You should now be able to deploy your application and get it to validate as XHTML Strict online from the W3C website.

Of course, this assumes that all of your own code is standard compliant. IIS can't do anything with code you provide - it will only guarantee to use the correct syntax when it generates code from ASP.NET controls, and other automatically generated content.

Valid XHTML 1.0! | Valid CSS! | WCAG Approved AA
Page design by: John P Scott - Hosting with: Netcetera