Validating XHTML with ASP.NET 2.0
With the go-live of ASP.NET 2.0, I've been actually using it at a level of more than "ooh, pretty new feature." I'm kinda of a standards nerd, so naturally I've been messing around with the XHTML output and making sure I like what I'm seeing. So far, so good. But I ran my page against the W3C's validator and it freaked out, complaining about form tags having names and the such. So I take a look at the source, and it looks good to me. So I go back to the validator, and run it one more time, this time enabling "Show Source." Ah, there's the problem. ASP.NET thinks that the validator is some ghetto browser from 1996 so it is sending it invalid markup.
The fix was pretty easy once I tracked it down. Simply update the browseCaps section of your web.config to tell ASP.NET about the W3C's user-agent. Here's the code I'm using:
<case match="W3C_Validator+">
browser=Netscape
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
</case>
Now when you validate your page, ASP.NET will send out the same HTML as it would if Firefox or IE were requesting the page. Now what I'd really like to do is tell ASP.NET to shove it, and spit out XHTML on unknown browsers. Anyone have any ideas?