Carl Camera

application/xhtml+xml Part Deux

My site is serving application/xhtml+xml once again thanks to the fine detective work by Microsoft IIS Tech Support Specialist WenJun.

After over twenty, yes twenty, emails, message board posts, and responses, the problem was determined to be ... my code. I was not handling correctly Request objects that did not contain an AcceptTypes object.

The W3C validator is not sending a AcceptTypes object (or identifying itself -- more on that in a minute.)

The problem with my original code appears to be that the Request.AcceptTypes object is not required to be sent by the User Agent. My original C# code would throw an exception when trying to access the Request.AcceptTypes.Length property.

So my new improved code for XHTML content negotiation is as follows:

if (Request.AcceptTypes != null)
  string strAppXhtmlXml = "application/xhtml+xml";
  foreach (string strMimeType in Request.AcceptTypes)
    if (strMimeType.IndexOf(strAppXhtmlXml) > -1)
      Response.ContentType = strAppXhtmlXml;

I've placed this code in the Page_Load() routine to handle content negotiaton.

I was rather surprised when I was told that the W3C Validator didn't send any type of AcceptTypes object. So I set up a log to capture the UA string, Version number, and the AcceptTypes strings for browsers as they visited my site.

Here's what the W3C Validator sends:

  • UA string "Unknown"
  • UA Version "0.0"
  • no AcceptTypes object

Weird that the W3C Validator doesn't even identify itself. I get the same from the Cynthia validator (emulating the Cynthia 1.0 browser.)

The downside to this whole exercise is that when you validate a page on my site, the W3C Validator will report that Vine Type is serving up text/html but it is, in fact, serving application/xhtml+xml for those User Agents that state they can accept it.