C# 是什么导致在 VS2005 中调试时 Page.Flush 上的 System.Web.HttpException 错误代码为 0x80070057?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/593048/
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
What causes the System.Web.HttpException with error code 0x80070057 on Page.Flush while debugging in VS2005?
提问by Ishmael
Here is the complete error message:
这是完整的错误消息:
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: The remote host closed the connection. The error code is 0x80070057.
System.Web.dll 中发生类型为“System.Web.HttpException”的异常,但未在用户代码中处理
附加信息:远程主机关闭了连接。错误代码是 0x80070057。
and the offending code:
和违规代码:
char[] buffer = oPage.HTML.HTML.ToCharArray();
Page.Response.Write(buffer, 0, buffer.Length);
Page.Response.Flush();
Page.Response.End();
The oPage.HTML.HTML is a string in a custom page object used by our app. The exception triggers on Page.Flush() and appears to be benign -- I just hit "continue" and everything goes along fine. This never appears at run time.
oPage.HTML.HTML 是我们的应用程序使用的自定义页面对象中的字符串。异常在 Page.Flush() 上触发并且似乎是良性的——我只是点击了“继续”,一切都很顺利。这在运行时永远不会出现。
I have chased many, many Google hits down many rabbit holes and have found nothing. Visual Studio 2005, Vista Ultimate (IIS7).
我追了很多很多谷歌,找到了很多兔子洞,一无所获。Visual Studio 2005、Vista Ultimate (IIS7)。
采纳答案by Chris B. Behrens
I've been dealing with this same error for a while now, and my understanding is that when Flush is called, there must be a connection on the other end, otherwise, this error is thrown. It's easy to get into a "fire-and-forget" kind of model when writing web pages, but when the client disconnects (in this debugging case, you're the client), there's nowhere to flush to.
同样的错误我已经处理了一段时间了,我的理解是,调用Flush时,另一端必须有连接,否则抛出此错误。编写网页时很容易陷入“即发即忘”的模型,但是当客户端断开连接时(在这种调试情况下,您是客户端),就无处可刷新到.
There are two solutions I've found to this:
我找到了两种解决方案:
- Wrap Response.Flush and catch the exception.
- Check Response.IsClientConnected before you call flush.
- 包装 Response.Flush 并捕获异常。
- 在调用flush之前检查Response.IsClientConnected。
I'm not 100% sure about the second one...I'm still in the process of checking that one out.
我对第二个不是 100% 确定......我仍在检查那个。
Good luck!
祝你好运!