I got assigned a rather annoying bug today whereby when a user using Firefox 7 went to a page that streamed a file for download, Firefox immediately stopped processing the page and returned the following error

Corrupted Content Error

A little bit of GoogleFu brought me to Firefox Bug #681140 - Corrupted Content error due to multiple Content-Disposition header field instances, new in Firefox 7.

There are a couple of reasons why this error will get thrown but the bottom line is Firefox thinks this is a form of response-smuggling and blocks it, in fact it doesn’t just block it, it denies any knowledge of anything to do with it, I could not for the life of me get Firefox to give me the response headers no matter what extension I used. In the end fiddler revealed the issue

content-disposition: attachment
Content-Disposition: attachment; filename="results.xls"

Fairly simple issue here, there are two Content-Disposition headers being sent to the browser and Firefox 7 throws it’s toys out of the pram if there is more than one.

Now, the cause.

I loaded up the controller that was generating these downloads and right enough, I found

Response.AddHeader("content-disposition", "attachment");
return File(content, format, filename);

I think you can see where I am going here. MVC is pretty good at removing a lot of the boiler plate we normally have to write and this is one of those cases. When you use the Controller.File method a number of headers are automatically set for you on the Response stream, if you provide a file name then one of those headers is Content-Disposition.

Ta-da, the source of the duplication.

So, when using FileResult in MVC, be very careful which additional headers you send out, check them in something like fiddler and don’t just assume that browsers in the future will accept malformed or duplicate headers.

 

Well, I was going to be writing up a review of DDD7 but after seeking out a good 3 column layout that I actually liked for WordPress last night (and failing) I have decided to take a new course of action.

I have been wanting to write a blog with ASP.NET MVC for quite some time, just never really found the time. I am now however, faced with a 7+ hour drive home from Reading and I think this would be the perfect time to write one, if nothing else just to see if I can actually do that in 7 hours :)

The tools I have with me are:

  • Laptop
  • Mobile Broadband Dongle
  • Visual Studio 2008
  • SQL Server 2008 Express
  • ASP.NET MVC
  • ADO.NET Entity Framework
  • Endless antics from Gary Short
  • Time

Update:

I knew it was adventurous and it was far more fun to be sociable in the car and help Colin Mackay out on the Developer Day Scotland website than it was to work on the blog. Saying that however, I think I am going to continue on with the blog and turn it into an MVC tutorial (or perhaps “Yet Another MVC Tutorial” better suits) which would allow me more time to develop it and actually provide something useful on the actual blog as well.

So while I don’t actually have a new blog yet, this has given me the idea to develop my own blog system in MVC and publish a tutorial along the way. Neat huh? (Well I think so)

DDD7 post will follow in the next couple of days but in the meantime, a big thanks to everyone who helped organise and run Developer Day 7 and a huge shout out to everyone who attended and made it what it was!

© 2011 Andy Gibson
Header image courtesy of Don Solo
Suffusion theme by Sayontan Sinha