Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.


I have a special case here:
My action method accepts one parameter, this parameter is expected to be a full url (e.g. http://www.somesite.com/article/onesite?hello=whatever&etc=blah). When working with old asp.net (oh, excuse me guys, I mean web forms) this works just fine, but when using asp.net mvc and preparing the required route ("/myaction/{inputUrl" with no constraints on inputUrl) it fails. If the url has any slashes I get an "Bad Request" exception. What should I do? Should I add a regex constraint on the passed in url to match a web url? What do you think dear SO Gus?

PS: The resource will be requested from an iPhone app, which means, I don't have any control over the coming url (i.e. I can't encode it!)

Thanks in advance.

share|improve this question
    
did you try to html.encode the querystring before sending? –  Razzie Nov 23 '09 at 13:15
1  
Use HttpUtility.UrlEncode –  Mauricio Scheffer Nov 23 '09 at 13:22
    
errr, yeah I meant that :) –  Razzie Nov 23 '09 at 13:30
    
actually the request will come from an iPhone app, i don't have control of encoding the url before sending it! –  Galilyou Nov 23 '09 at 14:19
    
then use encodeURIComponent to encode it with javascript –  Mauricio Scheffer Nov 23 '09 at 16:43

2 Answers 2

See this question http://stackoverflow.com/questions/591694/url-encoded-slash-in-url.

Even UrlEncode will not help here. The behaviour changes in MVC2.

share|improve this answer
    
I've edited .. check again please! –  Galilyou Nov 23 '09 at 14:21

Modify your route as /myaction/{*inputURL*}. This will catch all after myaction.

share|improve this answer
    
I already have a catch-all route set to something else. I can't have more than one catch-all routes. –  Galilyou Nov 24 '09 at 9:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.