1
votes

I am having an issue with (what I think is) the Response.WriteFile method in an ASP.NET/VB Web Forms application (which targets .NET 2.0) in IE 10 on a production server. Basically, this code has been in place and has been working great for many years until IE 10. Now, it works fine when I test it locally via Visual Studio, but when it's on a production server (Server 2008 R2, IIS 7), I get an error that the file cannot be downloaded. When I force it, I get a corrupt PDF. I'm using Crystal Reports X to generate the PDF. Anyone who is willing to help me with the right verbiage to research this issue will get my undying gratitude! I've tried all the compat modes of IE 10 with every variety. I've updated the browser definition files in my App_Browsers folder per Scott Hanselman http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx. As a still relative newbie developer, I'm not sure what I'm missing with how this works on IE 10 via VS but doesn't work when I put it in production.

Here is the code snippet in question:

    ...
    Response.ContentType = "application/pdf"
    Response.AddHeader("content-disposition", "attachment; filename=ThisReport_" & Server.UrlEncode(Me.ReportName.Text & "_" & Now.Month.ToString() & "_" & Now.Day.ToString() & "_" & Now.Year.ToString()) & ".pdf")

    Response.WriteFile(strFileName)
    ...

Thank you in advance for any help, guidance, or direction you can offer in solving this issue. I have this sprinkled in many places in my application, so finding a root-level fix would be preferable to fixing it in every place where it appears. Unfortunately, upgrading to .NET 4.5 is not currently an option.

4

4 Answers

4
votes

I am answering my own question in case someone else who may come along later could benefit from it. It turns out that as far as I can tell, there was a change in IE 10 that affects the response object in ASP.NET 2.0 (or other versions, I'm not sure). I was able to solve my issue by adding ...

    Response.ClearContent()
    Response.ClearHeaders()
    Response.Clear()
    Response.Buffer = True
    Response.ContentType = "application/pdf"
    Response.AddHeader("content-disposition", "attachment; filename=ThisReport_" & Server.UrlEncode(Me.ReportName.Text & "_" & Now.Month.ToString() & "_" & Now.Day.ToString() & "_" & Now.Year.ToString()) & ".pdf")
    Response.WriteFile(strFileName)        
    Response.End()

I tried using

    Response.Flush()
    Response.Close()

When I did that, I was getting the HTML page being spit out instead of the PDF content. This has solved the problem for me, though there is still much about the inner workings of ASP.NET and IIS that I have yet to learn. Feel free to add to this as necessary.

0
votes

Replace the Response.Flush() and Response.Close() with HttpContext.Current.ApplicationInstance.CompleteRequest()

0
votes

I had same problem where it work on my local machine but not working on PROD server which made to think that my local machine might got an update from Microsoft and PROD server has not been updated.The app we are testing was doing good on IE compatibility mode but was getting all kinds of weird things in IE 10.

I asked to update the prod server with the hot fix which was released by Microsoft 2 years back. But my server has 2.0 framework on it , so i asked them to move to framework 3.5 and apply this fix . Now the app does function fine and I am able to use without changing the browser mode to IE 10 compatibility mode.

Here is the link for the fix

http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2600088&kbln=en-us

0
votes

I was facing the same issue. I was using Response.Close(), I replaced it with "Response.End()" and it just did the job.