views:

37

answers:

2

How would I write a route in Asp.Net mvc to handle a url like this one for a Facebook page:

http://graph.facebook.com/http://codedojoboise.com/

I tried this route but get a 400 Bad Request error when I try to run it.

 routes.MapRoute(

            "LinkPreview",
            "LinkPreview/{path}",
            new {controller = "LinkPreview", action = "Get"});
A: 

Handling such characters in ASP.NET is a real PITA. You may checkout this or base64 encode it.

Darin Dimitrov
A: 

The characters : and / are being treated like parameter separators and so the route isn't matching. Try LinkPreview/{*path} which will tell it to use all the following characters as part of the parameter.

Chao
I tried the {*path}, which is a more correct route, but it's still blowing up if I include "http://" in the url
Andrew Hanson
Looked into Darin's links and it's being blocked by ASP at quite a deep level.
Chao
Looked into Darin's links and ":" being blocked by ASP at quite a deep level. You have 3 choices here. As Darin suggests you could Base64 encode it (which looks ugly), use the "requestPathInvalidCharacters" attribute as mentioned in the first link Darin posted (security issues) or if you can assume you're only going to be previewing http: pages just exclude the "http://" in the url and add it in server side. If not using Base64 you'll still need to use {*path} to deal with the "/"
Chao