English 中文(简体)
Writing file to users giving sporadic error in IE
原标题:

I have a very interesting issue with only specific IE implementations. I have an ASPX page that is used to write files down to the user, as part of the process the page uses the following code to write the file to the user.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=download" + System.IO.Path.GetExtension(oInfo.SupportingFilePath));
Response.ContentType = "application/octet-stream";
Response.WriteFile(Server.MapPath(oInfo.SupportingFilePath));
Response.End();

In 99.5% of the cases this works just fine, however, in certain rare circumstances within IE only on specific machines, the user is prompted to download the .aspx page, and/or is given an error message.

Anyone have an idea of what is going on here?

最佳回答

Per RFC2231, MIME headers parameter values have to be included in double quotes: http://www.ietf.org/rfc/rfc2231.txt (page 3, if you are interested). It should be something like "attachment;filename=""download" + System.IO.Path.GetExtension(oInfo.SupportingFilePath) + """");

问题回答

Although this should not be happening because you ve set the ContentType and content-disposition, I believe that IE s built-in MIME sniffing/handling is what is causing the problem here. Here are a couple of work-around/hacks you can try:

  • Add the file extension to the query string on the .aspx page that is transferring the file, i.e., http://blahblahblah/page.aspx?.ext
  • If you are using IE 8, you can specify another response header for "nosniff," as specified here.

I m still having issues with this, as documented here, but I hope one of these helps.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签