添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a page that generates a dynamic file for download, and sends it to the client using Response.BinaryWrite.

Everything seems to work fine, except when we moved it to a test server with SSL. The download happens in a new window, and what I'm seeing (in IE7/8 but not chrome or FF) is the tab opens, and closes, but no File Dialogue is shown.

Here's the complete header write:

Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/octet-stream"
        Response.AddHeader("Content-Length", abytFileData.Length.ToString)
        Response.AddHeader("cache-control", "private")
        Response.AddHeader("Expires", "0")
        Response.AddHeader("Pragma", "cache")
        Response.AddHeader("content-disposition", "attachment; filename=""" & pMsg!pstrFileName & """")
        Response.AddHeader("Accept-Ranges", "none")
        Response.BinaryWrite(abytFileData)
        Response.Flush()
        Response.End()

I thought for sure that my problem was what was mentioned here,

But my cache-control heade is correct. Any ideas?

Didn't see that post, but the link I provided is similar. In his question he didn't specify the cache-control header as anything, which was causing his problem. In mine I'm specifying cache-control as private, which should work. – Gaidin Dec 8, 2009 at 22:05

I've encountered the same problem and after some degree of investigation I found an article on codeproject suggesting that the download is being blocked by IE security settings. If you go to Tools->Internet Options->Security Tab and look at the Download options for the zone you are accessing, you need to change the "Automatic prompting for file downloads" to be Enabled. The "Internet" zone default setting for this is Disabled. Here's the link to the article I mentioned: http://www.codeproject.com/KB/aspnet/SecureFileDownload.aspx

Yep, this was the same conclusion I came to as well. Not very helpful in that the security setting for SSL connections is defaulted not to force the download prompt, and telling every single one of our users to change their security settings isn't really an option. What I ended up doing was instead of doing our download in a separate window, I did it in an iframe, so the IE security drop down warning was visible. – Gaidin Jan 15, 2010 at 14:08

Have you tried changing or removing your Expires or Pragma headers? The following code works for me when streaming PDFs over SSL:

Response.Buffer = True
Response.ClearContent()
Response.ClearHeaders()
Response.AddHeader("Cache-Control", "max-age=3")
Response.AddHeader("Pragma", "public")
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment; filename=file.pdf")
Response.AddHeader("Content-Length", mem_stream.Length.ToString)
Response.BinaryWrite(mem_stream.ToArray())
Response.Flush()
Response.End()
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.