2011-06-27 31 views
-1

我想編寫用於asp.net和asp的兩個函數。我想寫兩個版本。該功能用於URL編碼和解碼。現在,我遇到了一個新問題。這是如何工作server.urlencode。那麼,如何實現這個url編碼功能。我有asp的網址解碼功能。我嘗試爲asp獲取url編碼功能。所以,我可以在asp.net中編寫url編碼和解碼。請幫幫我。如何使用asp.net和asp之間的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

+0

您是否在ASP.NET頁面中使用C#或VB.NET? –

+0

[編碼功能,支持Unicode和工作在asp和asp.net]可能的重複(http://stackoverflow.com/questions/6491550/encoding-function-that-supports-unicode-and-works-in-both -Asp和-ASP網) –

回答

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

相關問題