Solved

urlencoding urldecoding urlreencoding translation error

Posted on 2011-03-01
2
509 Views
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.

http://www.myURL.com/gm/RunScript?queue%5Fid=18420&object=1%2E11%2E55340&script=worksphere%5Cworkflow%5Croutingwizard%5Fmultiple%2Epy&IKMUserID=scottst

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:

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

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

http://www.myURL.com/gm/RunScript?queue_id=18420&IKMUserID=scottst&object=1.11.55340&script=worksphereworkflow%0D%0Aoutingwizard_multiple.py

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:

http://www.myURL.com/gm/RunScript?queue_id=18420&IKMUserID=scottst&object=1.11.55340&script=worksphereworkflow
outingwizard_multiple.py

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.

George
0
Comment
Question by:wolfcoop
2 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 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}",
    incomingUrl.Scheme,
    incomingUrl.Host,
    incomingUrl.Port,
    incomingUrl.AbsolutePath,
    incomingUrl.Query);

Open in new window

0
 

Author Comment

by:wolfcoop
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.  
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Lync server 2013 Backup Service Error ID 4049 – After File Share Migration
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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 …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now