简体   繁体   English

在发送 HTTP 标头后,服务器无法 append header

[英]Server cannot append header after HTTP headers have been sent

I get this exception intermittently in my asp.net c# web application:我在我的 asp.net c# web 应用程序中间歇性地收到此异常:

Server cannot append header after HTTP headers have been sent.在发送 HTTP 标头后,服务器无法 append header。

And it caused by the application appending content to the pages response header after the page has been sent.它是由应用程序在页面发送后将内容附加到页面响应 header 引起的。 I am not sure why its intermittent but what I need to do is perform a check prior to the modification for the headers to check if the page has been sent.我不确定为什么它是间歇性的,但我需要做的是在修改标题之前执行检查以检查页面是否已发送。

Anyone know how I can achieve such a check?任何人都知道我怎样才能实现这样的检查?

There are 2 ways to do it:有两种方法可以做到:

  1. Subscribe to the PreSendRequestHeaders of HttpApplication and assume that the headers have been sent at this point.订阅HttpApplicationPreSendRequestHeaders并假设此时标头已发送。 Set a flag on the context and check for it everywhere在上下文上设置一个标志并在任何地方检查它

  2. The ugly solution: HttpResponse has a internal property called HeadersWritten .丑陋的解决方案: HttpResponse有一个名为HeadersWritten的内部属性。 Since it's internal you'll have to access it through reflection.由于它是内部的,因此您必须通过反射来访问它。 I'd recommand only to use this for debugging.我建议仅将其用于调试。 Check it before/after all the page lifecyle events and find out where the problem is.在所有页面生命周期事件之前/之后检查它并找出问题所在。 Don't leave this in production code不要将其留在生产代码中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发送 HTTP 标头后,服务器无法附加标头 - Server cannot append header after HTTP headers have been sent .NET,ASHX,“发送PDF Streem后,服务器无法在发送HTTP标头后追加标头” - .NET, ASHX, “Server cannot append header after HTTP headers have been sent” after sending PDF Streem Html.AntiForgeryToken()引发错误“服务器在发送HTTP标头后无法附加标头。” - Html.AntiForgeryToken() throws error “Server cannot append header after HTTP headers have been sent.” 发送HTTP标头后,服务器无法附加标头[DotNetZip lib] - Server cannot append header after http headers have been sent [DotNetZip lib] HTTP报头上传文件后,服​​务器无法追加标头 - Server cannot append header after HTTP headers have been sent uploading files HTTPS重定向导致错误“在发送HTTP标头后,服务器无法附加标头” - HTTPS Redirect Causing Error “Server cannot append header after HTTP headers have been sent” 在发送HTTP标头后,服务器无法附加标头c#excel inline - Server cannot append header after HTTP headers have been sent c# excel inline 发送HTTP标头后,服务器无法附加标头c#pdf内联 - Server cannot append header after HTTP headers have been sent c# pdf inline 发送HTTP标头后,服务器无法附加标头。 C#弹出窗口关闭 - Server cannot append header after HTTP headers have been sent. C# popup close 使用AntiForgeryToken发送HTTP标头后,服务器无法附加标头 - Server cannot append header after HTTP headers have been sent with AntiForgeryToken
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM