【发布时间】:2011-09-09 20:14:21
【问题描述】:
我继承了一个出现奇怪问题的经典 ASP 站点。在页面顶部,它重定向到 https 以实现安全连接。代码是:
<%
Response.Buffer = True
' Redirect to SSL if needed:
servername=Request.ServerVariables("SERVER_NAME")
scriptname=Request.ServerVariables("SCRIPT_NAME")
serverport=Request.ServerVariables("SERVER_PORT")
if serverport="80" and (InStr(servername, "192.168.1.") = 0 and servername <> "localhost") then
Response.Redirect "https://www.theurl.com" & scriptname & "?package=" + Request.QueryString("package")
else
'response.Write("Development testing")
end if
%>
此代码位于文件顶部。在此之前什么都没有。当我打开浏览器并加载我年龄的页面时:
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.
没有发生重定向。如果我重新加载页面或在出现错误后离开并返回,那么一切正常,直到我关闭浏览器并重新打开它。
如果这是在文件的顶部,如何已经写入标题?
更新:由 IE8 的视图源提供的完整源代码:
<font face="Arial" size=2>
<p>Response object</font> <font face="Arial" size=2>error 'ASP 0156 : 80004005'</font>
<p>
<font face="Arial" size=2>Header Error</font>
<p>
<font face="Arial" size=2>/path/file.asp</font><font face="Arial" size=2>, line 10</font>
<p>
<font face="Arial" size=2>The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
</font>
是的,前面的空格
【问题讨论】:
-
是否为 IIS 中的虚拟目录启用了缓冲?
-
@Sparky - 是的,它设置为 true。
-
当您收到错误消息时,如果您查看源代码,您会看到除错误消息之外的任何内容。文件中的任何字符都可能触发此操作。根据上面的代码,似乎不应该有,但不知何故,有些东西正在进入响应流。 CLEAR 没有帮助的事实让我认为它来自其他来源。
-
@Sparky - 我在上面列出了来源。
-
除空格外的所有内容均来自 VB 错误处理程序,可能是导致问题的空格。只是为了好玩,尝试只将重定向放入(只是一些通用站点)。如果可行,请重新添加每一行。还可以尝试删除 response.buffer=true,这可能会在标题中写入一些内容...
标签: asp-classic vbscript