HttpContext.Current.Response.Flush [英] HttpContext.Current.Response.Flush

查看:216
本文介绍了HttpContext.Current.Response.Flush的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我们公司面临新的麻烦,我找不到原因.单击打印"按钮时,某些用户(有时(并非总是))会收到此错误

Our company has facing a new trouble that i can't find why. Some users(sometimes only, not always) receive this error when click in my button Print

与远程主机通信时发生错误.错误代码为0x800703E3.

我一直在阅读有关此内容,并在Web上看到一些线程告诉我,该错误主要发生在带有IIS的环境中,等等.另请参见,另一个线程告诉我更改HttpContext.Current.Response.从HttpContext.Current.ApplicationInstance.CompleteRequest刷新, 但这只会带来更多问题,并使一切停止工作.不幸的是,即使在我们的服务器中,我也无法在公司的任何机器上重现此错误,但是我相信导致此错误的代码是这样的:

I've been reading about this, and see some threads on web that tells me, that this error is mostly occurs in the environment with IIS, etc. See too, another thread telling me to change HttpContext.Current.Response.Flush from HttpContext.Current.ApplicationInstance.CompleteRequest, but it just bring more problems, and made everything stop to work. Unfortunately i can't reproduce this error in any machine of my company, even in our server, but i believe the code that make this error is this :

public void printReport(ReportViewer reportViewer, ReportDataSource reportDataSource, LocalReport localReport)
{
    string mimeType;
    string encoding;
    string fileNameExtension;
    Warning[] warnings;
    string[] streamids;
    byte[] exportBytes = reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
    HttpContext.Current.Response.Buffer = true;
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.Expires = -1;
    HttpContext.Current.Response.ContentType = "application/pdf";
    HttpContext.Current.Response.AppendHeader("content-length", exportBytes.Length.ToString());
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + reportDataSource.Name + "." + fileNameExtension);
    HttpContext.Current.Response.BinaryWrite(exportBytes);
    HttpContext.Current.Response.Flush(); // i believe that flush causes this error.
    HttpContext.Current.Response.Close();
    HttpContext.Current.Response.End();
    HttpContext.Current.Response.Clear();
    reportViewer.Dispose();
    localReport.DataSources.Clear();
    localReport.Dispose();
    reportViewer = null;
    localReport = null;
    reportDataSource = null;
    streamids = null;
    exportBytes = null;
}

我的问题是我的项目在超过7页中使用了相同的方法,而且自一年以来首次只有一页会出现此错误.
这里有人遇到同样的问题,甚至可以帮助我吗?

My problem is that my project use this same method in more than 7 pages, and for the first time since one year, just ONE page make this error.
Someone here, have this same issue, or even can help me?

提前谢谢!







Web Developer

Web Developer

推荐答案

请检查线程.我认为这将帮助您解决问题

Please check thread . I think it will help you to slove the problem

http://stackoverflow.com/questions/5533068/httpcontext-throws-httpexception


这篇关于HttpContext.Current.Response.Flush的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆