ASP中错误“PRB: ASP 0156: 80004005 Header Err..
时间:2006-06-18 来源:jming
最近我在编写ASP代码的时候使用了Response.Redirect("apage.asp")时出现以下错误:
Response 对象 错误 'ASP 0156 : 80004005'
HTTP 头错误 /apage.asp,行 526 已将 HTTP 头输出到客户端浏览器。任何对 HTTP 头的修改都必须在输出页内容之前进行。
解决方法如下,在页面的最前端增加以下两句代码即可 <% @LANGUAGE = "VBScript" %>
<% Response.Buffer = True %> 问题分析如下: (微软站点获得,全英文暂无翻译)
This article was previously published under Q229657
Header Error
/VirtualDirectory/ASPPage.asp, line XX
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
Note This also occurs if you upgraded a computer that is running Microsoft Windows NT 4.0 to Microsoft Windows Server 2003.
An example of this is when an ASP page is processed that contains HTML tags or any other server-side scripts before a Response.Redirect statement.
The following properties and methods of the Response object of ASP write HTTP headers: Response.AddHeader
Response.CacheControl
Response.CharSet
Response.ContentType
Response.Expires
Response.ExpiresAbsolute
Response.Redirect
Response.Status
For example, to avoid this error with redirection, buffer or withhold the ASP page during its processing and issue the redirection after processing. There are two ways to accomplish buffering: on an application level or on a page level.
Note Ensure that the redirection is issued after all ASP scripts. If it is issued prior to ASP scripts, the ASP page redirects without processing the ASP code.
On an application level, all ASP pages within the Web application will be buffered when they are processed. To set buffering on an application level, follow these steps:
To set buffering on a page level, add code after the @LANGUAGE line on an ASP page as shown below:
Response 对象 错误 'ASP 0156 : 80004005'
HTTP 头错误 /apage.asp,行 526 已将 HTTP 头输出到客户端浏览器。任何对 HTTP 头的修改都必须在输出页内容之前进行。
解决方法如下,在页面的最前端增加以下两句代码即可 <% @LANGUAGE = "VBScript" %>
<% Response.Buffer = True %> 问题分析如下: (微软站点获得,全英文暂无翻译)
PRB: ASP 0156: 80004005 Header Error
View products that this article applies to.Article ID | : | 229657 |
Last Review | : | June 28, 2004 |
Revision | : | 1.0 |
SYMPTOMS
When you view an Active Server Pages (ASP) page in a browser, the following error can occur: Response object error 'ASP 0156 : 80004005'Header Error
/VirtualDirectory/ASPPage.asp, line XX
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
Back to the top |
CAUSE
This error occurs because the Web server uses an HTTP header to set the client browser. The Web server then tries to reset the client brower by using another HTTP header (for example, when an HTTP header sets the browser to content-type=text/html and then a redirection is issued after this). An example of this is when an ASP page is processed that contains HTML tags or any other server-side scripts before a Response.Redirect statement.Note This also occurs if you upgraded a computer that is running Microsoft Windows NT 4.0 to Microsoft Windows Server 2003.
An example of this is when an ASP page is processed that contains HTML tags or any other server-side scripts before a Response.Redirect statement.
The following properties and methods of the Response object of ASP write HTTP headers: Response.AddHeader
Response.CacheControl
Response.CharSet
Response.ContentType
Response.Expires
Response.ExpiresAbsolute
Response.Redirect
Response.Status
Back to the top |
RESOLUTION
To resolve this problem, set the HTTP Headers, such as Redirect statements or cookie information, before you send HTML output.For example, to avoid this error with redirection, buffer or withhold the ASP page during its processing and issue the redirection after processing. There are two ways to accomplish buffering: on an application level or on a page level.
Note Ensure that the redirection is issued after all ASP scripts. If it is issued prior to ASP scripts, the ASP page redirects without processing the ASP code.
On an application level, all ASP pages within the Web application will be buffered when they are processed. To set buffering on an application level, follow these steps:
1. | In the Microsoft Management Console (MMC), locate the Web site where your Web application resides. |
2. | Click to expand the Web site to display the virtual directories and Web applications. |
3. | Right-click the Web application, and then click Properties. |
4. |
On the Virtual Directory tab, click Configuration. Note If the Configuration button is unavailable, the virtual directory is not a Web application. Click Create to create the virtual directory to a Web application. |
5. | In the Application Configuration dialog box, on the App Options tab, click Enable buffering. |
<% @LANGUAGE = "VBScript" %> <% Response.Buffer = True %> Other ASP/Clientside scripts or HTML ... <% Response.Redirect %>In addition, you can use cookies to set buffering on a page level, as the following code demonstrates. This code snippet writes the cookie prior to the sending the <HTML> tag (element).
Response.Cookies("Name")=value <HTML> ...content... </HTML>
Back to the top |
STATUS
This behavior is by design and is a restriction of the HTTP protocol.Back to the top |
APPLIES TO
• | Microsoft Active Server Pages 4.0 |
• | Microsoft Internet Information Server 4.0 |
• | Microsoft Internet Information Services 5.0 |
Back to the top |
相关阅读 更多 +