Discussion Locked

Redirect doesn't work

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What would cause Response.redirect to not work? When this code is executed:

Response.write "
Before Redirect"
Response.Redirect "/files.asp"
Response.write "
After Redirect"

I get this:

Before Redirect
After Redirect

It seems to work everywhere but in my /admin folder.

6 replies

by stephen darlington

When your server replies to the client, it sends back a status and (optionally) some data.

The status, for a normal HTML file, is 200.

If you try to do a server-side redirect (like line two here) the reposnse code is something else.

So yourcode tells the server to send a HTML page *and* a redirect, and consequently gets confused (defaults to a 200).

If you delete the first and last line, it should work. Or if you want to display text on the screen while it's redirecting you'll probably have to use a client-side redirect (a tag in your header).

by kirkk

Thanks, this is helpful info.

Also, I discovered a rewritten header error, and that I can get around it by putting response.Buffer = true at the top of the page.

by michealirwin

if

"/files.asp"

is considered as relative addressing, then you don't have a subdirectory "files.asp". OTOH, if it's absolute addressing, as it should be, then you should look at your mapping for /admin, see what physical device it's on, and then see if there's a valid evaluation for /files.asp on that device. I suspect that "/admin" and "everywhere" are not on the same physical hard disk.

by peyison

You can't redirect if you've already sent data to the response buffer. This is being done in the first line. It is also the case if your redirect appears after any HTML.

All you have to do is clear the buffer before calling redirect:

Response.Clear
Response.Redirect "/files.asp"

If you're using ASP 3.0, you might also want to look into Response.Transfer and Response.Execute.

Hope this helps

This discussion is closed to new replies.