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.
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.
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:
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:
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?
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.
Janaka
Have you tried to use HttpUtility.UrlEncode()? Encode the url, pass it to the restExtension and then encode it back using HttpUtility.UrlDecode().
http://msdn.microsoft.com/en-us/library/system.web.httputility.htmlencode.aspx
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.
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:
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:
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:
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?
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
is working on a reply...