简体   繁体   English

经典的ASP重定向应该去哪里?

[英]Where should a classic ASP redirect go?

Should the code below go in the <head> ? 下面的代码应该放在<head>吗? Or should there be nothing else in the page besides the code below? 还是页面上除了下面的代码之外没有其他内容?

<%
    Response.Redirect "http://www.sitename.com/?" & Request.QueryString
%>

As long as you have response buffering enabled and you haven't called Response.Flush , you can perform a Response.Redirect anywhere in the page. 只要启用了响应缓冲并且没有调用Response.Flush ,就可以在页面中的任何位置执行Response.Redirect Buffering causes all ASP code to be executed before any of the page is sent to the browser. 缓冲导致所有ASP代码在将任何页面发送到浏览器之前执行。 Thus if you perform a redirect within the code after <head> , none of the HTML will be sent to the browser and thus the redirect header will be sent correctly. 因此,如果您在<head>之后的代码内执行重定向,则不会将任何HTML发送到浏览器,因此重定向头将被正确发送。

Buffering is typically enabled by default in IIS these days. 这些天通常默认情况下在IIS中启用缓冲。 To be safe, you could include this line near the top of your ASP page: 为了安全起见,您可以在ASP页面顶部附近添加以下行:

Response.Buffer = True

Classic ASP is server side code, <head> along with all html is client side code. 经典ASP是服务器端代码, <head>以及所有html是客户端代码。 If you have this line in a .asp page then there's no point in having anything else on the page as users will never get a chance to see it. 如果您在.asp页中有此行,则该页上没有其他内容是没有意义的,因为用户将永远没有机会看到它。

That line would make more sense if it was inside a conditional statement - eg 如果该行位于条件语句中,则更有意义-例如

<%
    If Request.QueryString("id") <> "" then
    Response.Redirect "http://www.sitename.com/?" & Request.QueryString("id")
    End If
%>

Here the user would only be bounced to another page if a value for id was provided in the url, otherwise any client side code in the page would be sent to the browser 在此,只有在url中提供了id值的情况下,用户才会跳到另一个页面,否则该页面中的所有客户端代码都将发送到浏览器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM