in

ASP.NET Weblogs

Phil Scott's WebLog

Quite exciting this computer magic

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?

Comments

 

Guest said:

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.
April 21, 2005 1:21 PM
 

Phil Scott said:

Hmmmm, good question. Let's see if I can't figure that out. Thanks for the suggestion.
April 21, 2005 1:43 PM
 

Matt Gibbs said:

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

<browsers>
<browser refID="default">
<capabilities>
<capability name="ecmascriptversion" value="1.5" />
<capability name="javascript" value="true" />
<capability name="w3cdomversion" value="1.0" />
</capabilities>
</browser>
</browsers>

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.
April 21, 2005 3:50 PM
 

Angela said:

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

September 4, 2007 9:12 AM
 

simarany61 said:

Buy consoles from MWgames.com.au. MWgames is an Australian wholesaler & retailer specializing in

<a href="www.mwgames.com.au">nintendo dsi xl</a>, DSi XL,3DS,Wii;PS3,XBOX 360 games and tablets etc.Quality products;Best Price;Satisfactory Service!

April 7, 2011 3:14 AM