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?

5 Comments

  • How would you encapsulate that in a .browser file? Using a .browser file is easier because you just copy it and drop it into website App_Browsers folder.

  • Hmmmm, good question. Let's see if I can't figure that out. Thanks for the suggestion.

  • A browser file like this would change the defaults for an application.



    &lt;browsers&gt;

    &lt;browser refID=&quot;default&quot;&gt;

    &lt;capabilities&gt;

    &lt;capability name=&quot;ecmascriptversion&quot; value=&quot;1.5&quot; /&gt;

    &lt;capability name=&quot;javascript&quot; value=&quot;true&quot; /&gt;

    &lt;capability name=&quot;w3cdomversion&quot; value=&quot;1.0&quot; /&gt;

    &lt;/capabilities&gt;

    &lt;/browser&gt;

    &lt;/browsers&gt;



    Or you could make the changes at the machine level in the default.browser file located in the browsers directory under config and then run aspnet_regbrowsers.

  • Could you provide an example without using the web.config file just a simple example in general (e.g: standalone page Default.aspx)

  • Buy consoles from MWgames.com.au. MWgames is an Australian wholesaler & retailer specializing in
    nintendo dsi xl, DSi XL,3DS,Wii;PS3,XBOX 360 games and tablets etc.Quality products;Best Price;Satisfactory Service!

Comments have been disabled for this content.