SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP Form Redirection

    What is the best way to redirect users after using an ASP form?

    This form is being called by three different sites and would like to send them to a customized page after submission. How can one distinguish what domain it's coming from?

    THANKS

  2. #2
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <form action="http://www.domain.com/form_results_page.asp" action="post">

    Then grab the form results from the previous page. I think this is what you are looking for, but I am only new with ASP.

    - Will

  3. #3
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you could use ASP's Response.Redirect Method to redirect someone to another page. Simply try this:

    at the beginning of your page:
    Code:
    <%Response.Buffer = True%>
    and where you want the redirect:
    Code:
    <%Response.Redirect("http://www.thesite.com/dir/page.asp")%>
    Also, you tell where a user is coming from in ASP by using this line of code:
    Code:
    <%dim var1
    var1 = Request.ServerVariables("HTTP_REFERER")%>
    The above line puts the page that the user came from into a variable called var1.

    If you still want to know how to do it in JavaScript, let me know.

    'Till next time...
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  4. #4
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by goober
    Well, you could use ASP's Response.Redirect Method to redirect someone to another page. Simply try this:

    at the beginning of your page:
    Code:
    <%Response.Buffer = True%>
    and where you want the redirect:
    Code:
    <%Response.Redirect("http://www.thesite.com/dir/page.asp")%>
    Also, you tell where a user is coming from in ASP by using this line of code:
    Code:
    <%dim var1
    var1 = Request.ServerVariables("HTTP_REFERER")%>
    The above line puts the page that the user came from into a variable called var1.

    If you still want to know how to do it in JavaScript, let me know.

    'Till next time...

    Once the HTTP_REFERER distinguishes what domain it's coming from I would like to direct the to the appropriate domain page.

    Example:

    abc.com uses ASP form and gets redirected to abc.com/thanks.htm

    nbc.com uses ASP form and gets redirected to nbc.com/thanks.htm

    Is this possible? with the current script it just redirects to one URL and I need to send the to a specific one depending on where they are coming from.

    Thanks in advance

    Hmiller

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a small note: I'm fairly sure you can use Response.Redirect without specifying the Response.Buffer value to True -- I believe True is the default value. I could be wrong, though.

  6. #6
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TWT, I believe you're mistaken. Even if not, you should always set the buffer property to true when you redirect, as suggested by most experts for various reasons. With that said..

    I'll show you how to make one specific page, and if the referrer contains "abc.com" it will add the 'site' QueryString to the URL with the value "abc". The submission page will then check for the QueryString and display the appropriate data.

    Also, I'm assuming you need to have an option if someone doesn't come from one of the "affiliates"? As in, a standard submission page? We can provide for that, too, if needed (very easily, in fact).

    As soon as you okay these things I'll begin to code for you.

    'Till next time..
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  7. #7
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, after looking it up, I am certain it is set to TRUE by default (page 273 of Beginning Active Server Pages 3.0, by Wrox Press), however it may be a good coding habit -- perhaps not.

    The only reason I can imagine for using it would be that some older versions of ASP, etc, require it. If not, well, then I guess it's just for organizational purposes...IE: I have this at the top of my script, so I must use Response.Redirect later on, although even Notepad has a simple search capability to handle this.

    Is there some kind of incompatibility with certain platforms/versions that requires this Response.Buffer declaration?

  8. #8
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris, I believe you have a valid point. I simply read somewhere to always declare response.Buffer = True, perhaps for security reasons? I am unsure as the reasons given were vague. Perhaps it was an older-version compatibility issue.

    Either way, I'm glad you've been able to prove me wrong, because it means not having to worry about inserting that nasty statement in the future.

    I need to learn not to disagree without evidence when it comes to these things. Will I ever learn?

    Thank you once again!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  9. #9
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I feel bad. I certainly was not looking for a confrontation -- maybe there is a reason for it, I'm not sure. I do know that more often than not experienced developers will put something like that in there -- perhaps for reference. IE: don't use var += 1, use var = var + 1, just to be ultra-clear. Spell it out.

    Heck, I dunno. You know more about ASP than I anyway -- I'm sure I'll learn many a lesson from you. I'm off topic now anyway -- I'll leave you two to your work

  10. #10
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris,

    No confrontation here. I'm sure we both have our merits. Also, I'm sure I'll learn just as much from you as you will from me.

    And another thing..Chris, what you did, I couldn't have asked for more. Any little thing like that will prompt my curiosity and I'll check up on it. It can only make me better.

    'Till next time..

    P.S now we're back to topic.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  11. #11
    SitePoint Enthusiast pinkstar's Avatar
    Join Date
    May 2001
    Location
    in a gallaxy far, far away
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Goober, if I am understanding this correctly, I can put the response.redirect("where_ever") in document one and then in document "where_ever" I could put the variable code?

    For example, I could create one error message page, error.asp, with *all* the templated error messages for display based upon the "HTTP_REFERER" ?

    If yes, then COOL! Got an example?

    Toni

    Originally posted by goober
    Well, you could use ASP's Response.Redirect Method to redirect someone to another page. Simply try this:

    at the beginning of your page:
    Code:
    <%Response.Buffer = True%>
    and where you want the redirect:
    Code:
    <%Response.Redirect("http://www.thesite.com/dir/page.asp")%>
    Also, you tell where a user is coming from in ASP by using this line of code:
    Code:
    <%dim var1
    var1 = Request.ServerVariables("HTTP_REFERER")%>
    The above line puts the page that the user came from into a variable called var1.

    If you still want to know how to do it in JavaScript, let me know.

    'Till next time...
    pb.

  12. #12
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    well, let's see..

    Well, I'll use your errors page example. You would put this code in the page that you want to redirect:
    Code:
    <%'Check to see if there was an error. 
    If (Error # 1) Then
    'Redirect to the page specifying the error code
    Response.Redirect "http://www.mydomain.com/errorpage.asp?Error=1"
    End If
    If (Error # 2) Then
    Response.Redirect "http://www.mydomain.com/errorpage.asp?Error=2"
    End If%>
    Then, here's something like what your error page would look like:
    Code:
    <%If Request.QueryString("Error") = "1" Then%>
    This is where the text would be displayed for error 1.
    <%ElseIf Request.QueryString("Error") = "2" Then%>
    This is where the text/html would be for error 2.
    <%Else%>
    This is where text would be if there was a different error number or if someone just surfed to the page without entering an error.
    <%End If%>
    ..and there you have it. That's about it.

    'Till next time..
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  13. #13
    SitePoint Enthusiast pinkstar's Avatar
    Join Date
    May 2001
    Location
    in a gallaxy far, far away
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: well, let's see..

    Goober, what would happen if I'm not going by error numbers?

    For example, in this script that I found on the net, there is a statement that checks if a user is logged in or not:

    <%
    if request.cookies("user-name") <> "" then
    if request.cookies("user-logged") = "Yes" then
    Else
    Response.redirect"error.asp?error=Please%20Login"
    End if
    Else
    Response.redirect"error.asp?error=Please%20Register"
    End if
    %>

    Could I easily change "Please%20Login" or "Please%20Register" to "1" or "2" like so:

    <%
    if request.cookies("user-name") <> "" then
    if request.cookies("user-logged") = "Yes" then
    Else
    Response.redirect"error.asp?error=1"
    End if
    Else
    Response.redirect"error.asp?error=2"
    End if
    %>

    And use your example below?

    Originally posted by goober
    Code:
    <%If Request.QueryString("Error") = "1" Then%>
    This is where the text would be displayed for error 1.
    <%ElseIf Request.QueryString("Error") = "2" Then%>
    This is where the text/html would be for error 2.
    <%Else%>
    This is where text would be if there was a different error number or if someone just surfed to the page without entering an error.
    <%End If%>
    [/B]
    Thanks a bunch for replying goober! I must sound like the newbie from h*ll.... lol!

    Toni
    pb.

  14. #14
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it's easier to just give your messages a #. Works better for me and is easier to code. Update it just the way you said.

    Also, I admire your questions! They give me a sense of purpose. I need people like you to keep me on my toes.

    If you have problems, let me know.

    Hope this helps! 'Till next time...
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  15. #15
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    goober;

    Is it possible for you to do it JavaScript?


    Thanks in advance...


    Originally posted by goober
    Well, you could use ASP's Response.Redirect Method to redirect someone to another page. Simply try this:

    at the beginning of your page:
    Code:
    <%Response.Buffer = True%>
    and where you want the redirect:
    Code:
    <%Response.Redirect("http://www.thesite.com/dir/page.asp")%>
    Also, you tell where a user is coming from in ASP by using this line of code:
    Code:
    <%dim var1
    var1 = Request.ServerVariables("HTTP_REFERER")%>
    The above line puts the page that the user came from into a variable called var1.

    If you still want to know how to do it in JavaScript, let me know.

    'Till next time...

  16. #16
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <a href="#" href="javascript:history.go(-1); return false;">

    ...to redirect...

    <script language="JavaScript">
    location.href = "http://www.yahoo.com";
    </script>

  17. #17
    SitePoint Member
    Join Date
    May 2001
    Location
    Leeds, UK
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Response.Buffer = True is used to instruct the server to execute all code before it is released to the client. Using is before a redirect is commonly seen as there might be code needed to execute successfully before the redirect can be executed.

    A neat tip is to use Response.Clear before a redirect instruction. This clears the buffer and ensures that no dodgy data is hanging about before the redirect executes.

    Response.Buffer is also useful if you are doing large db queries and want to provide users with some visible 'activity' by using a Response.Flush after x number of records displayed...

    Buffering can be turned on or off within IIS 4.0, but in IIS 5.0 it is turned on by default....Check webserver to see is turned on or not...simple test...use Response.Clear in your code....the webserver will moan if it is not turned on and indicate that buffering is turned off...

    Buffering can speed up perception that page loads fast, but can also degrade performance...Use as necessary...

    End of speech...

  18. #18
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!! That was very helpful, honestly. Now I'm glad I've got that cleared up.

    Thanks again.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •