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
EventType:Error EventSource: ASP.NET 2.0.50727.0 EventCategory:None Event ID:7777 Date:12/28/2011 Time:12:00:42 PM User: N/A Computer:Webserver Description: The description forEvent ID (7777)inSource( ASP.NET 2.0.50727.0) cannot be found. Thelocal 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 HelpandSupportfor details. The following information is part of the event: MESSAGE:Server cannot set status after HTTP headers have been sent. SOURCE:System.Web FORM: QUERYSTRING: TARGETSITE:Void set_StatusCode(Int32) STACKTRACE: at System.Web.HttpResponse.set_StatusCode(Int32 value) at Pha.Mvc.Web.StaticFileHandler.BeginProcessRequest(HttpContext context,AsyncCallback callback,Object state)in C:\Web\App\StaticFileHandler.cs:line 128 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously).
your action was executing, writing markup to response stream
the stream was unbuffered forcing the response headers to get written before the markup writing could begin.
Your view encountered a runtime error
Exception handler kicks in trying to set the status code to something else non-200
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
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!