Scott Hanselman

Internet Explorer and the Magic of Microsoft KB Article Q293792

September 16, 2003 Comment on this post [1] Posted in Web Services | PowerShell | Bugs
Sponsored By

Seems like a lot of my posts lately have started with something like "Here's a weird IE bug" or "Here's something odd in .NET" but...

Here's a weird IE thing.  We do a lot of Check Imaging and Statement stuff here, so if someone wants to go online and get an image of a check, they can.  We often use Web Services to talk to a Check Imaging Server.  Most often we retrieve PNG, JPEG, or GIF.  Sometimes, however, the client wants an Adobe Acrobat PDF. 

We'll make the SOAP call, get a PDF then stream it directly to the user (You don't want to save these kinds of things, for security purposes). 

Enter bug/feature Q293792.  Not a lot seems to have been written about this, and not a lot of people seem to care, but apparently when opening a full ActiveX embedding window (to host Acrobat, etc) IE makes either THREE or TWO requests for the content.  This is apparently "by design" as URLMON and MSHTML have trouble communicating.  So, MSHTML sends a request to "sniff" for the MIME type to figure out what app to load. 

Other than being a bandwidth hog, this wouldn't be a big deal - except, when the generation/retrieval of a PDF is an expensive operation involving a WS call to the back end. (Wow, a production Web Service! Madness! Heresy! ;) )

What's interesting is that IE changes the UserAgent HTTP Header to "contype" during the probe, obstensibly so we can simple return the MIME/type and not the actual data.

So, we need to handle that...something like (in classic ASP "psuedo-code"):

  If Instr(1, UserAgent, "contype") > 0 Then
   'Just send the mime/type
   Response.ContentType = "application/pdf"
   Response.End
  End If

So, that's not too bad.  But, even the "Fixed" versions of IE still send TWO requests.  So, we want to detect the second request and not return the whole thing again. 

Here's the other ODD point.  For reasons unknown to me, IE doesn't include the Accept-Language header when making this second call, so, we have them use what has already been sent by saying "Not-Modifed":

  Dim Language
  Language = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
  If Language = "" then
   Response.Clear
   Response.ContentType = "application/pdf"
   Response.AddHeader "Last-modified", "Mon, 01 Sep 1997 01:03:33 GMT"
   Response.Status = "304 Not Modified"
   Response.End
  End If

Ah, the fun of supporting older versions of IE.  I think we need an updated IE Roadmap. 

The future of browsing, dear readers, is up in the air, IMHO.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
July 13, 2004 23:01
Some MIE browser / plug-in configurations do not send the request twice. Mine doesn't, and of my co-workers about half their pc's do not. But I haven't been able to figure out why. They just send the 2nd request, the one without the HTTP_ACCEPT_LANGUAGE. If I use the fix outlined, we don't get the file, since that is the only request. :-(

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.