mvc - server cannot set status after http headers have been sent


Hi ,
I have a MVC application which throws this wired error sometimes "
Here is the full error

         Event Type:        Error
Event Source:    ASP.NET 2.0.50727.0
Event Category:                None
Event ID:              7777
Date:                     12/28/2011
Time:                     12:00:42 PM
User:                     N/A
Computer:          Webserver
The description for Event ID ( 7777 ) in Source ( ASP.NET 2.0.50727.0 ) cannot be found.
The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer.
You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details.
The following information is part of the event: MESSAGE: Server cannot set status after HTTP headers have been sent.
: System.Web
: Void set_StatusCode(Int32)
:    at System.Web.HttpResponse.set_StatusCode(Int32 value)
Pha.Mvc.Web.StaticFileHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) in C:\Web\App\StaticFileHandler.cs:line 128
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously).
edit | flag
William Patrick
Asked on: Dec 30, 2011 at 2:52AM

1 Answers


The Possible causes may be

  1. your action was executing, writing markup to response stream
  2. the stream was unbuffered forcing the response headers to get written before the markup writing could begin.
  3. Your view encountered a runtime error
  4. Exception handler kicks in trying to set the status code to something else non-200
  5. Fails because the headers have already been sent.

If you could still encounter runtime errors in View binding e.g. null reference exceptions.

A better solution for this is to ensure that

Response.BufferOutput = true;

before any bytes are sent to the Response stream. e.g. in your controller action or On_Begin_Request in application. This enables server transfers, cookies/headers to be set etc. right the way up to naturally ending response, or calling end/flush.

edit | flag
Gokul A
Answered on: Dec 30, 2011 at 2:56AM

Post your Answer


Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags