Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > response.redirect vs. server.transfer issues without buffering

Reply
Thread Tools

response.redirect vs. server.transfer issues without buffering

 
 
michael sorens
Guest
Posts: n/a
 
      08-02-2007
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")


 
Reply With Quote
 
 
 
 
michael sorens
Guest
Posts: n/a
 
      08-07-2007
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>
=======================================


 
Reply With Quote
 
 
 
 
michael sorens
Guest
Posts: n/a
 
      08-07-2007
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.
 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      08-07-2007
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.


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      08-07-2007
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.


 
Reply With Quote
 
michael sorens
Guest
Posts: n/a
 
      08-13-2007
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.

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      08-13-2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to fread_s or ifstream.read without buffering/caching! gustavo.samour@gmail.com C++ 3 05-21-2009 05:03 PM
animation without flickering/double buffering dhavalshah Java 0 12-26-2008 02:16 AM
Working around buffering issues when writing to pipes sven _ Python 1 04-22-2008 12:42 PM
Atomic line-reading without buffering japhy C Programming 11 03-03-2007 11:16 AM
Double-Buffering Without drawImage? Lash Rambo Java 5 07-14-2004 11:32 PM



Advertisments