Navigation


RSS: Matt Pavey RSS Feed



Saturday, April 14, 2007 @ 5:44 pm,ASP.Net,Matt Pavey

I ran into an issue the past couple of days regarding prompting the user with a OPEN/SAVE prompt for exporting data. It's been working for as long as I can remember, but yesterday I upgraded the site to use an SSL certificate so everything would be secure. But in doing so the OPEN/SAVE prompt for one of my pages no longer worked and was causing an IE error.

Further research confirmed that there are some known IE bugs regarding setting the ContentType and Content-Disposition to support forcing an attachment to be streamed directly to the user via the OPEN/SAVE prompt, opposed to having to actually save the file to disk and worry about disk space, permissions, etc.

Anyways, since it took me a while to pin down getting this to work with HTTPS (SSL) I thought I'd go ahead and share the code in case anyone else ran into the same thing.

Response.ClearHeaders()
Response.ContentType = "application/csv"
Response.AppendHeader("Content-Disposition", "attachment; filename=Registrations.csv")

The Response.ClearHeaders() line was the line I had to add to solve the problem.

Apparently this is only a problem with IE browsers and I saw several posts about it and all of them had different solutions proposed, such as setting the Pragma and other header related values, but I couldn't get any of those to work. So I thought if I couldn't change the header values I would simply just clear them all out and set exactly what I needed, which was the ContentType and the Content-Disposition.

After adding that single line of code the page now works for HTTP and HTTPS and from my testing works in all major browsers (IE, Firefox, etc.).


Thursday, April 12, 2007 @ 3:11 pm,VB.Net,Matt Pavey

Remember the "Using" block is a convenient, shorthand notation for the Try-Finally block. "Using" and "End Using" ensures that Dispose is called even when an exception occurs - and that's a good thing.


The opinions expressed on this website are my personal opinions
and do not represent my employer's or my clients' views in any way.