Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Janaka Lakmal 25 posts 72 karma points
    Sep 29, 2011 @ 13:24
    Janaka Lakmal

    Pass a URL to restExtension

    I have a method called using restExtension. I want to pass URL as a parameter. As URL has "/" it is giving me an error because it treats as separate parameters. Ex : Base/GetJSONPage/About-Us/What-We-Do. I want About-Us/What-We-Do as one parameters where as umbraco treat is as two parameters.

    I tried using overload methods but restExtension does not recognize them and giving me Ambiguous methods error. Can't use any characters instead of "/" as user gets confused. 

    Thinking about creating a handler but if anybody has solution for this it would be appriciated.



  • Markus Johansson 1756 posts 5136 karma points c-trib
    Sep 30, 2011 @ 07:32
    Markus Johansson

    Have you tried to use HttpUtility.UrlEncode()? Encode the url, pass it to the restExtension and then encode it back using HttpUtility.UrlDecode().


  • Janaka Lakmal 25 posts 72 karma points
    Oct 03, 2011 @ 17:27
    Janaka Lakmal

    Thank you for your reply. I don't think it is possible to encode URL without changing the /Base. I rather go with generic handler though the URL is not pretty.


  • Øyvind Kristiansen 14 posts 54 karma points
    Oct 07, 2011 @ 08:53
    Øyvind Kristiansen

    I bumped into this same problem recently, where I needed to pass a URL as a parameter to base, and oddly I wasn't able to find a solution to this anywhere.

    My solution to this problem was kind of hacky, but it worked for me. I am calling the base URL from JavaScript, so i use encodeURIComponent on the url to get rid of most of the characters causing problems:

                longUrl = encodeURIComponent(longUrl);

    However, the per cent and dot characters remain after this, and will still cause a problem. This is where the "hacking" comes in. I replace these characters with other characters which (hopefully) won't appear in most URLs:

                longUrl = longUrl.replace(/\%/g, "€");
                longUrl = longUrl.replace(/\./g, "£");

    This seems to be sufficient for the rest extension method to receive the parameter, but it's a mess at this time, of course, so I have to process the string to restore it to the original. Or in my case, to a URIComponent-encoded string:

                longUrl = longUrl.Replace("€", "%");
                longUrl = longUrl.Replace("£", ".");

    You may, of course, decode this to end up with the original url.

    I see that you mention that you can't ask the user to replace the characters themselves, but would it be possible to use an event handler to do the replacing and pass the request on to base?

  • Janaka Lakmal 25 posts 72 karma points
    Oct 07, 2011 @ 11:14
    Janaka Lakmal

    thank you Kristiansen. Very good idea. I will try with an event handler. If it does not work call with javascript would definitely sort the problem

Please Sign in or register to post replies

Write your reply to: