urlencoding urldecoding urlreencoding translation error

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.

Who is Participating?
Todd GerbertIT ConsultantCommented:
>> 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

wolfcoopAuthor Commented:
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.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.