This page deals with the causes of the following error:
Response object error 'ASP 0156 : 80004005'
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content
When the webserver sends a webpage to the client the communication consists of two parts - the headers and the body.
The first part is the HTTP header which includes such information as the HTTP status (usually 200 - OK, or 404 - Object Not Found),
the content type (text/html) and the cookies. All of these things can be set programmatically by using the methods of the
Response Object. An example is the commonly used Response.Redirect which sends a HTTP 302 - Object Has Temporarily Moved
header to the client.
After this header information the actual webpage content is sent (usually beginning with a DOC type declaration or a plain <html> tag).
After the first part of the body has been sent additional header information can not be sent to the client. Attempting to send
additional header content to the client (eg by setting cookie, or attempting a Response.Redirect()) will result in the error message above.
Thus the following code will generate an error:
Response.Write("This is a test")
Solution Part 1 - Re-arrange your code
The first step towards solving the problem involves re-arranging code so as to generate all header information prior to sending body
information to the client. Whilst this may sometimes involve time-consuming re-engineering of badly coded pages it results IMHO
in better program code. Personally I've never seen an application that requires body information to be written to the client prior to
sending header information.
Solution Part 2 - Enable Page Buffering
The second step towards solving this problem involves enabling page buffering. Whilst this step will solve the problem by itself it treats
merely the symptoms of the problem, not the underlying cause (badly written code).
When page buffering is enabled the web-server holds onto all content (headers and body) until it has
finished processing the page, or the response.end or response.flush methods are invoked. This allows the web-server to accumulate all the header
and body information for the page and then send them in the correct order.
The additional benefit of page buffering is that it speeds up page execution. Because the web-server does not need to worry
about sending bits and pieces of information to the client it can concentrate on executing the page, and then managing the TCP
connections to the client. Whilst, to the client it may appear that the page is loading slower (because things aren't arriving in
dribs and drabs) actual page loading is faster.
Page buffering may be enabled at the page level:
<%@ Language=VBScript %>
Response.Buffer = True
or may be enabled at the application level:
Back to FAQ Listing |