views:

108

answers:

4

I am using classic asp with vb script. The code for downloading the excel file is:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=ExportedData.xls"
Response.Write "<table><tr><td>1</td></tr></table>"

Then it works fine with the firefox, or any other down loader like orbit down loader. But I get error in IE 6.0/7.0/8.0.

The message is:

Internet Explorer cannot download myasppage.asp from secure.siteurl.com.

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

so what would be the problem?

FYI: I pass a query string parameter ysnDownload=1 to myasppage.asp page. & if it is passed then and then only it will have the ContentType as application other wise it will have default type (text/html).

A: 

If you're on SSL (secure.siteurl.com uses SSL right?) then Internet Explorer is a bit picky with temporary files.

The headers I usually sent with it in this case are:

Cache-Control: public, must-revalidate
Pragma: hack
Htbaa
Ya, I had also tried that but :-(
Vikas
You're sure these additional headers overwrite any other pre-set values? In my case I'm making sure no headers have been sent yet.
Htbaa
Along the same lines as this one I have had success with the following:Response.AddHeader "pragma", "no-store, no-cache, must-revalidate"
pflunk
Tried: Response.AddHeader "pragma", "no-store, no-cache, must-revalidate" but didn't work
Vikas
+2  A: 

I think the clue may be in the "secure.siteurl.com". My guess is you are sending this over https?

In which case you may be falling foul of a "bug" in the way IE handles downloads of this type. It downloads such documents to the cache then transfers or opens them from there. However when content is downloaded over https and does not specify caching or explicitly declare that the item should not be served from the cache the document is not saved in the cache. This can break the download save or open mechinism.

Try setting the Expires and CacheControl properties of the Response object to allow a very short window of caching. For example:-

Response.Expires = 1
Response.CacheControl = "private; max-age=10"
AnthonyWJones
Yes, I am using https protocol. And I tried above line but didn't work. I am in big trouble!!
Vikas
If I use http then it works but if I use https then it creates problem, Exactly as you said. But why so? Is there any solution for problem?
Vikas
As I said in my reply; try pragma:hack
Htbaa
I've run afoul of this IE bug too, and ended up just sending it by http because I couldn't find a workaround (with client's permission of course)
mgroves
@Vikas: I've described why the problem occurs in my answer, I've also included a solution.
AnthonyWJones
A: 

Are you clearing and ending?

Response.Clear
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=ExportedData.xls"
Response.Write "<table><tr><td>1</td></tr></table>"
Response.End
Eduardo Molteni
ya, I am doing both
Vikas
A: 

http://forums.asp.net/t/1224596.aspx

This line of code should work for you, just clear the headers also before exporting the file. Reponse.ClearHeaders();

schrodinger's code