简体   繁体   中英

ASP.NET File Download problem

In our application we often have a button that will perform a post back, get data, convert it into excel/PDF, and stream it to the client via Response.Write or Response.BinaryWrite. This works perfectly fine when we are in a popup or not.

We just implemented a new feature that creates a msg file. However, we are getting an error when streaming to the client (same code as before) - "Internet explorer cannot open this site". We redirect to another page with a query string parameter stating which file to get the bytes for and stream it to the client.

Has anyone experienced this before? This feature works fine on the dev machines but in staging (Server 2003, IIS 6) it's broken and throwing this error

Could it be a rights issue? The excel/pdf you are creating - is it getting saved to a file and then being forced download? If yes, the WEB-User-IIS a/c needs to have access to the file/folder area where the file is being saved.

I faced a similar problem when I was creating Excel files using Microsoft.Excel or Excel (COM) from ASP.Net - it would work on my Dev machine (I am the local admin) but wouldn't work on the server.

The file on the server gets created under the Administrator's account and thus Web-User-IIS account wouldn't have access to that file and thus would be unable to access it. There is an option within IIS to change the user under whose accounts Excel runs through IIS.


Also, application/octet-stream as the MIME type has always worked fine for me when pushing out files for download.

I've done things very similar to that. Without seeing your code it's impossible to say exactly what your problem is but here's a couple of things to check:

  • Are you setting the Response.ContentType to the correct MIME type for the file?
  • Are you calling Response.End() once you have written the bytes of the file out. If not then the page HTML may be appended to the file which will corrupt it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM