简体   繁体   中英

ASP-Classic - how can I clear out a redirect header put there by Response.Redirect?

I'm working with a compiled VB6 object called by an ASP page. Response buffering is on. My code calls another compiled VB component, which may call Response.Redirect(), but continue executing and return control to my code. I may then want to call Response.redirect myself. However, this seems to create an array for the header, rather than overwriting the previous Url:

Code:

  Call m_oResponse.Redirect("http://google.com")
  Call m_oResponse.Redirect("http://yahoo.com")

Resulting http response:

 HTTP/1.1 302 Object moved
 ...
 Location: http://google.com,http://yahoo.com
 ...
 Date: Wed, 23 Mar 2011 18:14:17 GMT
 Connection: keep-alive

I tried Response.Clear, but this doesn't seem to affect the headers.

As far as I know Response.Redirect() terminates the processing of the page and does the redirect immediately. Generally your code cannot continue processing afterwards so there is nothing you can do to avoid the redirect.

MSDN says:

Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored. However, this method does send other HTTP headers set by this page indicated by the original URL to the client. An automatic response body containing the redirect URL as a link is generated.

http://msdn.microsoft.com/en-us/library/ms524309.aspx

The only way I can think that you could get code to continue executing afterwards would be to invoke a compiled COM component or some other external process as that would not be affected by the page execution being terminated.

If the VB component you mention is an external component and not just another ASP file included with an <!--#include file="other_script.asp"--> directive then it will continue executing but your calling ASP page won't.

Do you have the source for the compiled component?

ie could it be rewritten to, instead of causing the redirection itself, just simply return the URL to redirect to?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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