Passing Quotes in a URL Call

Discussion in 'ASP General' started by Wayne Wengert, Jan 15, 2004.

  1. Using ASP 3.0

    I want to dynamically build a call to another asp page and include some
    parameters as part of the call. The basic format of the call is something
    like::

    "<a href='mypage.asp?id=" & theid & "&location='" & thelocation &
    "'>GO</a>"

    where there is a single quote followed by a double quote following the
    ...location=... and vica-versa after the variable

    My problem is that the variable thelocation can include a single quote or a
    double quote. I tried Server.URLEncode and that didn't work. I got a string
    that ended up causing a Page Not Found (it encoded the dot in the page name
    and that didn't work)

    How can I encode the data so that quotes will be accepted in this type of
    call?

    Wayne
     
    Wayne Wengert, Jan 15, 2004
    #1
    1. Advertisements

  2. Kevin

    Kevin Guest

    Did you decode the URL at the other end when you encoded
    it?

    Try the following code before you reconstruct the call to
    the page..

    <%
    Function myURLDecode(strString)
    strString = Replace(strString, "%2F", "/")
    strString = Replace(strString, "%7C", "|")
    strString = Replace(strString, "%3F", "?")
    strString = Replace(strString, "%21", "!")
    strString = Replace(strString, "%40", "@")
    strString = Replace(strString, "%5C", "\")
    strString = Replace(strString, "%23", "#")
    strString = Replace(strString, "%24", "$")
    strString = Replace(strString, "%5E", "^")
    strString = Replace(strString, "%26", "&")
    strString = Replace(strString, "%25", "%")
    strString = Replace(strString, "%2A", "*")
    strString = Replace(strString, "%28", "(")
    strString = Replace(strString, "%29", ")")
    strString = Replace(strString, "%7D", "}")
    strString = Replace(strString, "%3A", ":")
    strString = Replace(strString, "%2C", ",")
    strString = Replace(strString, "%7B", "{")
    strString = Replace(strString, "%2B", "+")
    strString = Replace(strString, "%2E", ".")
    strString = Replace(strString, "%2D", "-")
    strString = Replace(strString, "%7E", "~")
    strString = Replace(strString, "%2D", "-")
    strString = Replace(strString, "%5B", "[")
    strString = Replace(strString, "%5F", "_")
    strString = Replace(strString, "%5D", "]")
    strString = Replace(strString, "%60", "`")
    strString = Replace(strString, "%3D", "=")
    strString = Replace(strString, "%27", "'")
    strString = Replace(strString, "+", " ")
    strString = Replace(strString, "%22", Chr(34))
    myURLDecode = strString
    End Function
    %>
     
    Kevin, Jan 15, 2004
    #2
    1. Advertisements

  3. Dan Boylett

    Dan Boylett Guest

    "Wayne Wengert" <> wrote in message
    news:%...
    > Using ASP 3.0
    >
    > "<a href='mypage.asp?id=" & theid & "&location='" & thelocation &
    > "'>GO</a>"
    >
    > where there is a single quote followed by a double quote following the
    > ..location=... and vica-versa after the variable
    >
    > My problem is that the variable thelocation can include a single quote or

    a
    > double quote. I tried Server.URLEncode and that didn't work. I got a

    string
    > that ended up causing a Page Not Found (it encoded the dot in the page

    name
    > and that didn't work)


    Sounds like you were possibly trying Server.URLEncode in the wrong place...

    I would say this should work :

    Response.write "<a href='mypage.asp?id=" & Server.URLEncode(theid) &
    "&location='" & Server.URLEnCode(thelocation) & "'>GO</a>"
     
    Dan Boylett, Jan 15, 2004
    #3
  4. Thanks Dan. You were right. I used the URLEncode on the whole call instead
    of just the pieces that needed it.

    Wayne

    "Dan Boylett" <> wrote in message
    news:...
    >
    > "Wayne Wengert" <> wrote in message
    > news:%...
    > > Using ASP 3.0
    > >
    > > "<a href='mypage.asp?id=" & theid & "&location='" & thelocation &
    > > "'>GO</a>"
    > >
    > > where there is a single quote followed by a double quote following the
    > > ..location=... and vica-versa after the variable
    > >
    > > My problem is that the variable thelocation can include a single quote

    or
    > a
    > > double quote. I tried Server.URLEncode and that didn't work. I got a

    > string
    > > that ended up causing a Page Not Found (it encoded the dot in the page

    > name
    > > and that didn't work)

    >
    > Sounds like you were possibly trying Server.URLEncode in the wrong

    place...
    >
    > I would say this should work :
    >
    > Response.write "<a href='mypage.asp?id=" & Server.URLEncode(theid) &
    > "&location='" & Server.URLEnCode(thelocation) & "'>GO</a>"
    >
    >
     
    Wayne Wengert, Jan 15, 2004
    #4
  5. Very Handy function. Thanks

    Wayne

    "Kevin" <> wrote in message
    news:03ff01c3db69$8b182410$...
    > Did you decode the URL at the other end when you encoded
    > it?
    >
    > Try the following code before you reconstruct the call to
    > the page..
    >
    > <%
    > Function myURLDecode(strString)
    > strString = Replace(strString, "%2F", "/")
    > strString = Replace(strString, "%7C", "|")
    > strString = Replace(strString, "%3F", "?")
    > strString = Replace(strString, "%21", "!")
    > strString = Replace(strString, "%40", "@")
    > strString = Replace(strString, "%5C", "\")
    > strString = Replace(strString, "%23", "#")
    > strString = Replace(strString, "%24", "$")
    > strString = Replace(strString, "%5E", "^")
    > strString = Replace(strString, "%26", "&")
    > strString = Replace(strString, "%25", "%")
    > strString = Replace(strString, "%2A", "*")
    > strString = Replace(strString, "%28", "(")
    > strString = Replace(strString, "%29", ")")
    > strString = Replace(strString, "%7D", "}")
    > strString = Replace(strString, "%3A", ":")
    > strString = Replace(strString, "%2C", ",")
    > strString = Replace(strString, "%7B", "{")
    > strString = Replace(strString, "%2B", "+")
    > strString = Replace(strString, "%2E", ".")
    > strString = Replace(strString, "%2D", "-")
    > strString = Replace(strString, "%7E", "~")
    > strString = Replace(strString, "%2D", "-")
    > strString = Replace(strString, "%5B", "[")
    > strString = Replace(strString, "%5F", "_")
    > strString = Replace(strString, "%5D", "]")
    > strString = Replace(strString, "%60", "`")
    > strString = Replace(strString, "%3D", "=")
    > strString = Replace(strString, "%27", "'")
    > strString = Replace(strString, "+", " ")
    > strString = Replace(strString, "%22", Chr(34))
    > myURLDecode = strString
    > End Function
    > %>
     
    Wayne Wengert, Jan 15, 2004
    #5
    1. Advertisements

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. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    5,108
    Hermit Dave
    Sep 22, 2004
  2. Chris
    Replies:
    1
    Views:
    14,102
    Oisin
    Mar 24, 2006
  3. Lawrence Tierney

    Multiline quotes - escaping quotes - et al

    Lawrence Tierney, Dec 24, 2003, in forum: Java
    Replies:
    3
    Views:
    4,722
    Andrew Thompson
    Dec 24, 2003
  4. jOhn
    Replies:
    1
    Views:
    417
    Phlip
    Jan 29, 2008
  5. Richard Sandoval
    Replies:
    5
    Views:
    351
    7stud --
    Apr 26, 2011
Loading...

Share This Page