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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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 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…

743 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