response.redirect vs. server.transfer issues without buffering
response.redirect vs. server.transfer issues without buffering
am 02.08.2007 21:10:02 von m_j_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")
Re: response.redirect vs. server.transfer issues without buffering
am 03.08.2007 18:55:33 von Jon Paal
"I simply get a page refresh of the current page. Why is this? "
Try isolationg the problem by creating a simple file with a redirect statement.
Then post the code that doesn't work and folks may be able to assist.
Re: response.redirect vs. server.transfer issues without buffering
am 07.08.2007 20:38:07 von m_j_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 & "]
"
%>
Hello world
<%
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 &
"
"
Response.Redirect "http://www.sun.com/"
'Server.Transfer "http://www.sun.com/"
End If
On Error Goto 0
%>
=======================================
Re: response.redirect vs. server.transfer issues without buffering
am 07.08.2007 21:18:03 von m_j_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.
Re: response.redirect vs. server.transfer issues without buffering
am 07.08.2007 21:23:41 von reb01501
michael sorens wrote:
> 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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: response.redirect vs. server.transfer issues without buffering
am 07.08.2007 21:46:27 von reb01501
michael sorens wrote:
> 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.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: response.redirect vs. server.transfer issues without buffering
am 13.08.2007 17:32:06 von m_j_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 & "]
"
%>
Hello world
<%
On Error Resume Next
BeginDate=CDate(Request.QueryString("cboBegin"))
If Err.Number <> 0 Then
Response.Write "Err=" & Err.Number & " [" & Err.Description & "]" &
"
"
'Response.Redirect "/ms_temp/test2.asp?foo=bar"
Server.Transfer "/ms_temp/test2.asp"
Response.Write "Err=" & Err.Number & " [" & Err.Description & "]" &
"
"
End If
On Error Goto 0
%>
==================================
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.
Re: response.redirect vs. server.transfer issues without buffering
am 13.08.2007 18:01:57 von reb01501
michael sorens wrote:
> 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.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.