How to use url encoding function between asp.net and asp

浪子不回头ぞ 提交于 2019-12-25 17:37:41

问题


I want to write the two functions that is used for asp.net and asp. I want to write two version. This function is used url encode and decode. Now, I got a new problem. This is how to work server.urlencode. So, how to implement this url encode function. I have url decode function for asp. I try to get url encode function for asp. So that, I can write url encode and decode in asp.net. Please, help me.

This is url decode function.

Function URLDecode(sConvert)
    Dim aSplit
    Dim sOutput
    Dim I
    If IsNull(sConvert) Then
       URLDecode = ""
       Exit Function
    End If

    ' convert all pluses to spaces
    sOutput = REPLACE(sConvert, "+", " ")

    ' next convert %hexdigits to the character
    aSplit = Split(sOutput, "%")

    If IsArray(aSplit) Then
      sOutput = aSplit(0)
      For I = 0 to UBound(aSplit) - 1
        sOutput = sOutput & _
          Chr("&H" & Left(aSplit(i + 1), 2)) &_
          Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
      Next
    End If

    URLDecode = sOutput
End Function

I got this.


回答1:


VBScript is a hog when it comes to string parsing so here is the same decode done in JScript:

<script language="JScript" runat="server">
// This function decodes the any string
// that's been encoded using URL encoding technique
function URLDecode(psEncodeString) 
{
  return unescape(psEncodeString); 
}
</script>

http://www.kamath.com/codelibrary/cl006_url.asp

.NET has HttpServerUtility.UrlEncode and HttpServerUtility.UrlDecode functions built in.

http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx



来源:https://stackoverflow.com/questions/6490247/how-to-use-url-encoding-function-between-asp-net-and-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!