后HTTP标头已被送往服务器不能追加头 [英] Server cannot append header after HTTP headers have been sent

查看:243
本文介绍了后HTTP标头已被送往服务器不能追加头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我断断续续得到这个例外在我的asp.net C#中的Web应用程序:

I get this exception intermittently in my asp.net c# web application:

在HTTP标头已被送往服务器不能追加头。

Server cannot append header after HTTP headers have been sent.

和它引起的应用程序附加内容到页面发送后的页面响应头。我不知道为什么它的间歇,但我需要做的是执行前修改的标题,以检查是否页面已发送了一张支票。

And it caused by the application appending content to the pages response header after the page has been sent. 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?

推荐答案

有2种方式来做到这一点:

There are 2 ways to do it:


  1. 订阅 preSendRequestHeaders 的HttpApplication 并假设标头在被送往这一点。在上下文中设置一个标志,到处检查它

  1. Subscribe to the PreSendRequestHeaders of HttpApplication and assume that the headers have been sent at this point. Set a flag on the context and check for it everywhere

丑陋的解决方案:
的Htt presponse 有一个叫做内部属性 HeadersWritten 。由于它的内部,你将不得不通过反射来访问它。我只推荐使用这种用于调试。 /前检查所有的页面生命周期事件之后,并找出问题的所在。不要在生产code离开这个

The ugly solution: HttpResponse has a internal property called 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

这篇关于后HTTP标头已被送往服务器不能追加头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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