response.redirect vs. server.transfer issues without buffering

M

michael sorens

I am attempting to retrofit a large quantity of existing ASP code with
a Response.Redirect call in case of error.

I found that if I add "Response.Buffer = true" near the top of the file then
the Response.Redirect will work. (So I surmised that the default is false,
because it did not work without that.) Curiously, with the line omitted, I do
not get a server error saying that headers have already been written; I
simply get a page refresh of the current page. Why is this?

I am particularly wondering if I could do this without activating buffering.
I read that Server.Transfer should be able to do it, but I get the same "not
working" symptom as above, i.e. a page refresh of the current page. Any
suggestions here?

My system details:
VBScript engine is version 5.6
SERVER_SOFTWARE value is "Microsoft-IIS/4.0" (which one reference indicated
means "IIS4.0 with ASP 2.0")
 
M

michael sorens

Here is a minimal sample. With a command line of
http://www.me.com/redirect.asp?cboBegin=xx the Response.Redirect call is
redirecting the page. If I comment that line out and uncomment the
Server.Transfer the result is just a refresh of the current page. Similarly,
if I change Response.Buffer to false, then either Response.Redirect or
Server.Transfer simply cause a refresh of the current page. I am wondering if
there are some global IIS settings that might cause this behavior, or is it
something else...?

=======================================
<%@ LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = true
Response.Write "QueryString [" & Request.QueryString & "]<br><br>"
%>


<HTML>
<BODY>
<p>Hello world</p>

<%
On Error Resume Next
BeginDate=CDate(Request.QueryString("cboBegin"))
If Err.Number <> 0 Then
Response.Write "Err=" & err.number & ", cboBegin=" &
Request.QueryString("cboBegin") & ", CDate(cboBegin)=" & BeginDate &
"<br><br>"
Response.Redirect "http://www.sun.com/"
'Server.Transfer "http://www.sun.com/"
End If
On Error Goto 0
%>

</BODY>
</HTML>
=======================================
 
M

michael sorens

One other approach I am considering on this topic: Is it possible with
VBScript embedded in an ASP file to programatically abort? That is, instead
of redirecting to an error page, I am considering just clearing the buffer,
emitting some error text, but then I want the rest of the ASP file to be
skipped upon returning from the error handling method.
 
B

Bob Barrows [MVP]

michael said:
Here is a minimal sample. With a command line of
http://www.me.com/redirect.asp?cboBegin=xx the Response.Redirect call
is redirecting the page. If I comment that line out and uncomment the
Server.Transfer the result is just a refresh of the current page.
Similarly, if I change Response.Buffer to false, then either
Response.Redirect or Server.Transfer simply cause a refresh of the
current page. I am wondering if there are some global IIS settings
that might cause this behavior, or is it something else...?

With Buffer set to false, header and content (response.writes) is sent
immediately to the client. Once the header is sent, it cannot be
changed. Therefore, the redirect header is ignored by the client.

Transfer only works for transferring to a file _on the same server_. It
cannot be used to transfer to a different web server. It makes sense
doesn't it? Transfer not only transfers control to the new page, it also
transfers context, context which can only be found on that server.
Anways, check for a new error when attempting to transfer to the
www.sun.com - you'll see the error being masked by the on error resume
next
 
B

Bob Barrows [MVP]

michael said:
One other approach I am considering on this topic: Is it possible with
VBScript embedded in an ASP file to programatically abort? That is,
instead of redirecting to an error page, I am considering just
clearing the buffer, emitting some error text, but then I want the
rest of the ASP file to be skipped upon returning from the error
handling method.

Response.Clear clears the buffer (Buffer needs to be True)
Response.End ends the response.
 
M

michael sorens

I was not aware of the restriction to files on the same server, but rest
assured I had tested both avenues (on the same server and on a different
server) in my ignorance.

Per your suggestion I find there is an additional error being masked from
this code:
==================================
<%@ LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = true
Response.Write "QueryString [" & Request.QueryString & "]<br><br>"
%>

<HTML>
<BODY>
<p>Hello world</p>

<%
On Error Resume Next
BeginDate=CDate(Request.QueryString("cboBegin"))
If Err.Number <> 0 Then
Response.Write "Err=" & Err.Number & " [" & Err.Description & "]" &
"<br><br>"
'Response.Redirect "/ms_temp/test2.asp?foo=bar"
Server.Transfer "/ms_temp/test2.asp"
Response.Write "Err=" & Err.Number & " [" & Err.Description & "]" &
"<br><br>"
End If
On Error Goto 0
%>

</BODY>
</HTML>
==================================
The Response.Redirect works; the Server.Transfer fails with error 438
[Object doesn't support this property or method].
I tried 3 variations of the argument to Server.Transfer (domain qualified,
root-based (as shown), and relative; all gave the same error.
 
B

Bob Barrows [MVP]

michael said:
The Response.Redirect works; the Server.Transfer fails with error 438
[Object doesn't support this property or method].
I tried 3 variations of the argument to Server.Transfer (domain
qualified, root-based (as shown), and relative; all gave the same
error.

So I went back to your original post and found this:
My system details:
VBScript engine is version 5.6
SERVER_SOFTWARE value is "Microsoft-IIS/4.0" (which one reference
indicated means "IIS4.0 with ASP 2.0")

Server.Transfer was introduced in IIS 5.0. As the error message says:
the Server object did not have a Transfer method in IIS 4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top