vb.net Response.WriteFile 在生产服务器上不工作 IE 10
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15606063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Response.WriteFile not working IE 10 on production server
提问by VeganBrandon
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.
我在生产服务器上的 IE 10 中的 ASP.NET/VB Web 窗体应用程序(面向 .NET 2.0)中的 Response.WriteFile 方法(我认为是)有问题。基本上,这段代码已经就位,并且在 IE 10 之前已经运行了很多年。现在,当我通过 Visual Studio 在本地测试它时它工作正常,但是当它在生产服务器(Server 2008 R2,IIS 7)上时,我收到无法下载文件的错误。当我强制它时,我得到一个损坏的 PDF。我正在使用 Crystal Reports X 生成 PDF。任何愿意用正确的措辞帮助我研究这个问题的人都会得到我不朽的感激!我已经尝试了各种 IE 10 的所有兼容模式。我已经根据 Scott Hanselman 更新了 App_Browsers 文件夹中的浏览器定义文件http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx。作为一个仍然相对的新手开发人员,我不确定我在通过 VS 在 IE 10 上如何工作时缺少什么,但是当我将它投入生产时却不起作用。
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.
预先感谢您为解决此问题提供的任何帮助、指导或方向。我在我的应用程序中的很多地方都有这个,所以找到一个根级修复比在它出现的每个地方修复它更可取。不幸的是,目前无法升级到 .NET 4.5。
回答by VeganBrandon
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 ...
我正在回答我自己的问题,以防以后可能出现的其他人可以从中受益。事实证明,据我所知,IE 10 中的更改影响了 ASP.NET 2.0(或其他版本,我不确定)中的响应对象。我能够通过添加...来解决我的问题
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.
当我这样做时,我得到的是 HTML 页面而不是 PDF 内容。这已经为我解决了这个问题,尽管我还有很多关于 ASP.NET 和 IIS 的内部工作原理的东西我还没有学习。如有必要,请随意添加。
回答by Nick C
Replace the Response.Flush() and Response.Close() with HttpContext.Current.ApplicationInstance.CompleteRequest()
用 HttpContext.Current.ApplicationInstance.CompleteRequest() 替换 Response.Flush() 和 Response.Close()
回答by Akarsh Kolanu
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.
我有同样的问题,它在我的本地机器上工作,但在 PROD 服务器上不工作,这让我认为我的本地机器可能从 Microsoft 获得更新,而 PROD 服务器尚未更新。我们正在测试的应用程序在 IE 兼容性方面做得很好模式,但在 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.
我要求使用 Microsoft 2 年前发布的修补程序更新 prod 服务器。但是我的服务器上有 2.0 框架,所以我要求他们转移到框架 3.5 并应用此修复程序。现在该应用程序运行正常,我无需将浏览器模式更改为 IE 10 兼容模式即可使用。
Here is the link for the fix
这是修复的链接
http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2600088&kbln=en-us
http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2600088&kbln=en-us
回答by Muhammad Awais Dilber
I was facing the same issue. I was using Response.Close(), I replaced it with "Response.End()" and it just did the job.
我面临同样的问题。我正在使用 Response.Close(),我用“Response.End()”替换了它,它就完成了这项工作。

