Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Server cannot append header after HTTP headers have been sent. [556]

$
0
0
Hi All,

I have recently started using Web API (version 4.0.20710.0) and have created an ActionFilterAttribute that sets some caching headers in the OnActionExecuted method.

I also have a IHttpModule that sets some headers in the PostRequestHandlerExecute event using request.AppendHeader when this happens I get the following error

Exception: System.Web.HttpException
Message: Server cannot append header after HTTP headers have been sent.
Source: System.Web
at System.Web.HttpResponse.AppendHeader(String name, String value)

This does not seem to be the case in MVC 3 (haven't tested this in MVC 4). Not sure if I am missing something but looking at the ASP.NET pipeline this should not be the case http://msdn.microsoft.com/en-us/library/ms178473(v=vs.100).aspx

Any help would be greatly appreciated.
Comments: Please ignore my previous comment as its incorrect. I have tried to repro your scenario and as Yishai mentioned following are more details: 1. Web API response policy is Buffered(this is the default): PostRequestHandlerExecute can add the header as you expect. I have attached a project which shows this working. 2. Web API response policy is Streamed: PostRequestHandlerExecute is not able to add the header and I see the error you mentioned. In the attached project, uncomment the line in WebApiConfig.cs file to repro your scenario. @afalkows: Can you please let us know if you are using Streamed mode? If yes, you could probably avoid enabling Streamed mode for the whole app (as i am doing in my attached project) and instead selectively do streamed mode for only some requests. This would be possible as the 'UseBufferedOutputStreamed' method is supplied with HttpResponseMessage and from which you can get HttpRequestMessage and do checks.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>