response.redirect vs. server.transfer issues without buffering

Discussion in 'ASP General' started by michael sorens, Aug 2, 2007.

  1. 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")
     
    michael sorens, Aug 2, 2007
    #1
    1. Advertising

  2. 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>
    =======================================
     
    michael sorens, Aug 7, 2007
    #2
    1. Advertising

  3. 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.
     
    michael sorens, Aug 7, 2007
    #3
  4. 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.
     
    Bob Barrows [MVP], Aug 7, 2007
    #4
  5. 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.
     
    Bob Barrows [MVP], Aug 7, 2007
    #5
  6. 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.
     
    michael sorens, Aug 13, 2007
    #6
  7. 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.
     
    Bob Barrows [MVP], Aug 13, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin
    Replies:
    3
    Views:
    559
    Cowboy \(Gregory A. Beamer\)
    Jul 31, 2003
  2. Harsh Thakur

    Response.Redirect vs Server.Transfer

    Harsh Thakur, Aug 18, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    793
    Harsh Thakur
    Aug 18, 2003
  3. RAJ
    Replies:
    2
    Views:
    1,809
  4. Sal
    Replies:
    1
    Views:
    1,006
  5. David C. Holley

    server.execute/response.redirect/server.transfer

    David C. Holley, Jan 17, 2004, in forum: ASP General
    Replies:
    6
    Views:
    456
    David Holley
    Jan 18, 2004
Loading...

Share This Page