ArcaneTek from LowTek

Wednesday, June 28, 2006

Debugging the Internet Explorer View Source problem with Fiddler and fixing ASP.NET

Summary: This article shows how to figure out why Internet Explorer's View Source command didn't work on an XML document, how it was debugged using Fiddler, and the ASP.NET fix.

You ever try "View Source" on an XML document and get this dialog box that says "The XML source file is unavailable for viewing."?

I got this while creating an ASP.NET page that was outputting RSS. I ran Fiddler and spied on what the web server was returning:

I didn't really see anything wrong with the output, so the next step was Process of Elimination to try removing HTTP headers until the problem didn't occur anymore. So I chose Rules -> Automatic Breakpoints -> After Responses from Fiddler's menus. This causes Fiddler to break-in and effectively pause the HTTP session so that you can change the response before the browser gets it:

Eventually, I tried deleting the Vary: * HTTP header by selecting it, right-clicking, and choosing "Remove Header". This was the header causing the problem! I did a quick check around various RSS feeds on the Internet and I didn't see any that used this header. For the detailed info on what this header is for, see the HTTP spec.

It seems that ASP.NET was outputting this Vary: * HTTP header because I used the following in my page:

<%@ Page Language="C#" CodeFile="t.aspx.cs" Inherits="t_aspx" %>
<%@ OutputCache Duration="300" VaryByParam="*" %>

The reason I used VaryByParam="*" was because my page is dependent on all of the QueryString parameters.

Eventually, after digging around, I found these two pieces of documentation:

So if you put the following in your ASP.NET web.config file, it will no longer output the Vary: * header and then your cached XML output will be View Source-able in Internet Explorer.

<?xml version="1.0"?>
      <!-- Don't send the Vary: * HTTP header when
        VaryByParam="*" is used because IE
        does not cache pages with Vary: *
        in the HTTP headers. -->


Post a Comment

<< Home