ASP.NET: XHTML Strict Validation
From Wiki
Summary: ASP.NET 2.0 has problems when trying to validate a XHTML 1.0 Strict page using the W3 validation service.
If you are using an XHTML Strict DOCTYPE e.g.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Then you might notice that your ASP.NET pages don't validate correctly when using the W3 validator service. This is because when the request comes in from the service, ASP.NET treats the service as a down level browser and the HTML that is generated doesn't comply to the standard that the DOCTYPE needs. If you view the page from a browser and then sent the generated HTML, it would validate but this doesn't help with direct requests from the w3 service.
To get around this problem, you need to create an ASP.NET folder in your project called "App_Browsers". Then, inside that folder create a file named"w3cvalidator.browser" and add the following code:
- <browsers>
- <!--
- Browser capability file for the w3c validator
- sample UA: "W3C_Validator/1.305.2.148 libwww-perl/5.803"
- -->
- <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>
Now, when the w3 service requests your page, it won't be treated as a low level browser and the correct HTML will be rendered so that your page will validate (assuming you haven't made any errors!).
This Hack is part of the ASP.NET Hacks collection


