当我的网站建立PDF并打开对话框让用户保存或打开它时,我不断收到此错误消息。远程主机关闭连接 - asp.net MVC3
这是完全错误的ELMAH:
The remote host closed the connection. The error code is 0x800704CD
现在,我相当肯定用户不会看到这个错误,但我的日志充满他们的,我只是想摆脱它!
点击我的页面上的链接链接到构建PDF的控制器操作。下面是该代码的最后一部分:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=filename.pdf");
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
HttpContext.Current.Response.Flush();
stream.Close();
HttpContext.Current.Response.End();
Return View();
我认为这是因为动作试图进行响应结束后抛出错误的Response.End()
。这听起来正确吗?如果是这样,我能做些什么来阻止它?
即使用户没有看到错误,我看到它,它必须解决!
谢谢 - 让我知道如果你需要更多的信息
是的,你不能在响应结束后返回View(),因为它试图在已经发回给用户的响应中发送更多的HTML。 – mclark1129