Skip to content

Instantly share code, notes, and snippets.

@gwobcke
Last active June 21, 2023 09:38
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gwobcke/2773779 to your computer and use it in GitHub Desktop.
Save gwobcke/2773779 to your computer and use it in GitHub Desktop.
ASP seems to lack a URL Decode function but has a URL Encode function available. Here is a function that can decode any URL Encoded URL or variable.
<%
FUNCTION URLDecoder(str)
'// This function:
'// - decodes any utf-8 encoded characters into unicode characters eg. (%C3%A5 = å)
'// - replaces any plus sign separators with a space character
'//
'// IMPORTANT:
'// Your webpage must use the UTF-8 character set. Easiest method is to use this META tag:
'// <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
'//
Dim objScript
Set objScript = Server.CreateObject("ScriptControl")
objScript.Language = "JavaScript"
URLDecoder = objScript.Eval("decodeURIComponent(""" & str & """.replace(/\+/g,"" ""))")
Set objScript = NOTHING
END FUNCTION
%>
@kobibentata
Copy link

This function is great and simple and it really helped me in solving an issue I had with URL encoding.
But I do have one important note about it:
The name of the function should be change from URLDecode, as this is a built-in function in Classic ASP and unfortunately, there is no way to override an existing function (like in JavaScript, C and so on).
I would slightly change it to URLDecoder and that would easily solve the problem described here.
(*) Don't forget to change this name also inside the function (the return value)!

@icewindq
Copy link

many thanks. it's simple and helpful.

@therbta
Copy link

therbta commented Nov 24, 2022

Thanks from 2012 :) I'm surprised that Classic ASP doesn't have URL decoding.

@badursun
Copy link

🤌🤌🤌🤌🤌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment