Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


urlencoding urldecoding urlreencoding translation error

Posted on 2011-03-01
Medium Priority
Last Modified: 2012-05-11
Ok I will try and make this brief.  Very complicated application using C# ver 1.1(that’s right), Javascript, Python (that’s right), Java, SHTML, and a couple of other bolted on applications built in C#.  Here is the deal.

Inside the shtml shell I have a c# page that calls to some internal javascript objects that POST a form behind the scenes to a server (IIS 6.0).  After the form is posted an internal call to a Python file is made, and a URL to that file gets created and urlencoded.  The encoding looks great.  Below is my logging of the script call.  Please take special note of the encoding right after the word workflow "%5Croutingwizard%5Fmultiple%2Epy" which unencoded is this "\routingwizard_multiple.py" the script file to be executed.


The URL from above gets sent through C# code back to the web server, an auto login process for the application is used, and the URL gets decoded and re-coded during that process and added to a URL value of TARGET.  The decoded URL is below:


That above URL is fine and looks good.  The auto login process re-encodes the URL variables to this value, which is the problem.


It has interpreted the \r at the beginning of \routingwizard_multiple.py to be a line feed.   So the URL when it is decoded makes this which results in a time out because it is not executing the Python script call.  The last URL is this:


Notice the line return now, and the script name outingwizard_multiple.py.  

This breaks the application.  Now it is time for the really good stuff.  This works on a production system and does not have the URL hiccup.  Code is a direct copy of that working code.  Verified Encoding is the same in the same places config files, meta tags, IIS globalization.  Versions of IIS are the same with the same service pack.  Globalization settings are the same on the servers and the servers’ operating systems match to the correct service pack.  IIS 6 on windows server 2003 service pack 2.  Everything I can think of to check I have verified as I have been bogged down on this for over a week.

Does anyone have any suggestions, or directions that I could head down as I am totally stumped on this one.  Putting the URL into encoder and decoders gets proper results.  Why would it translate the \r in one instance, and not the other?  Is there a way around this short of renaming files?  I would like to find the underlying problem so I can make certain other script calls will not be miss-encoded.

Thanks, I know it is long and convoluted explanation, and I appreciate you die hard challengists that love a good one, cause here is a doozy.

Question by:wolfcoop
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 33

Accepted Solution

Todd Gerbert earned 2000 total points
ID: 35013515
>> I will try and make this brief
Well, at least you tried. ;)

Your question was a little difficult to follow, so let me make sure I understood correctly: you have a C# application receiving the string "http://www.myURL.com/home/index.asp?target=https://www.myURL.com/gm/RunScript?queue_id=18420&object=1.11.55340&script=worksphere\workflow\routingwizard_multiple.py&IKMUserID=scottst" and upon trying to URLEncode it the backslashes are being interpreted as escape sequences?

How are you URL encoding it?  I don't have .Net 1.1, so I can't test - but on 2.0 HttpUtility.UrlEncode() behaves correctly (as I would expect, escape sequences would only be interpreted in string literals, not string variables).

Best thing I can suggest is to re-encode it by assigning it to a Uri object, and then re-assembling the components of the Uri object into a string.  The Uri object is available in .Net 1.1, but I can't be sure of it's behavior, but on .Net 2.0 the "Query" property of the Uri object seems to be correctly encoded.  Interestingly, Uri.ToString() does not URLEncode the query string, hence the need to use String.Format to reassembly the individual pieces.

string testUrl = @"http://www.myURL.com/home/index.asp?target=https://www.myURL.com/gm/RunScript?queue_id=18420&object=1.11.55340&script=worksphere\workflow\routingwizard_multiple.py&IKMUserID=scottst";

Uri incomingUrl = new Uri(testUrl);

string reEncoded = string.Format("{0}://{1}:{2}{3}{4}",

Open in new window


Author Comment

ID: 35013624
ok so after a bit more digging the call is coming from a VB 6 application that behind the scenes executes a non-response script request on the server.  The URL encode of the VB code, man am I in the wrong Zone :-(, autologs in via a cookie and executes the script, while the front end C#, Shtml application shell is looking at a dashboard page, leaving the front end application to do more work, while the script exectuion runs in the back end.  Again same code as on working production servers, so the URL encode call of the VB 6 code is going to different reacting encoders.  The URL Encode from VB 6 of the production server behaves differently.  Rather than spending anymore time trying to fix and synchronize the servers, I am doing a simple string Search (%0D%0) on the encoded URL and Replace(%5Cr) if the string exists. None of the URLs passed back in should contain a \r line feed as they are URL's so my workaround hack is if it exists it has to be a "\r" that was misinterpreted.  I am giving you credit because your idea to break the URL and recompile the string parts is really what I am doing, just in the VB 6 app.  Did I say this thing was a monster.  

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question