如何在asp.net和asp之间使用url编码功能

时间:2011-06-27 08:21:13

标签: asp.net asp-classic url-encoding

我想编写用于asp.net和asp的两个函数。我想写两个版本。该函数用于url编码和解码。现在,我遇到了一个新问题。这是如何工作server.urlencode。那么,如何实现这个url编码功能。我有asp的url解码功能。我尝试获取asp的url编码功能。所以,我可以在asp.net中编写url编码和解码。求你帮帮我。

这是url解码功能。

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

我得到this

1 个答案:

答案 0 :(得分:0)

VBScript在字符串解析方面很重要,所以这里是在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内置了HttpServerUtility.UrlEncode和HttpServerUtility.UrlDecode函数。

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

相关问题