views:

297

answers:

4

www.yoursite.com/image/http://images.google.com.ph/images/nav_logo7.png

What I need to know here is the Controller Action, and the Global.asax routes

+1  A: 

I'd start by not trying to embed a second URL into your route.

In cases where I have to use a URL as part of a route, I replace the slashes with an alternate character so you don't have issues with the interpertation of the URL as a malformed route (i.e.~,|,etc.) then retranslate these with some string replaces in the controller. And if possible, I'd ditch the HTTP:// and assume the route is a URL by convention.

So your route would become something like:

www.yoursite.com/image/images.google.com.ph~images~nav_logo7.png

Bob Palmer
+4  A: 

If you want to send a URL as a parameter on a URL you need to URL Encode it first

In c# use Server.UrlEncode(string) from the System.Web namespace

So your example will look like:

www.yoursite.com/image/http%3a%2f%2fimages.google.com.ph%2fimages%2fnav_logo7.png

And your route pattern could be:

routes.MapRoute(
    "image",
    "image/{url}",
    new { controller = "Image", action = "Index", url = "" }
);
TFD
+8  A: 

The colon : character is not valid in the path segment of the URL, so you'll have to either encode it, or remove it entirely. After that, you can use the {*routeValue} syntax to specify that the route value should be assigned the remainder of the URL.

routes.MapRoute( 
    "Image", 
    "image/{*url}", 
    new { controller = "Image", action = "Index" } 
); 

For the url http://www.yoursite.com/image/images.google.com.ph/images/nav_logo7.png , the above route will execute ImageController.Index() with a url argument of "images.google.com.ph/images/nav_logo7.png". How you choose to deal with the protocol (encode/remove) is up to you.

Also keep in mind that a url authority can be made up of a domain name and a port number, separated by : (www.google.com:80) which would also need to be encoded.

Richard Szalay
TFD
My original answer assumed that the requirement dealt with URIs that were already deemed valid. As such, no additional encoding would be required.
Richard Szalay
A: 

URL-encoded slash in URL - Stack Overflow

This is same problem and solved solutions.

1st solution. Replace "://" to "/". Routing url pattern "image/{scheme}/{port}/{*url}".

2nd solution "image/{*url}" set *url value base64.

takepara