tags:

views:

149

answers:

3

I'm trying pass in a url as a paramter to my controller like this:

//Passed in via url like this: 
//http://www.mydomain.com/Puzzle/ContinuePuzzle/{insert url here}
public ActionResult ContinuePuzzle(string url)
{
    return View("PuzzleWrapper", 
                 (object)_PuzzleService.ContinuePuzzle(url);
}

Whenever I try this I get a http 400 Bad Request error. I've tried UrlEncoding it, but it still doesn't like it. Any suggestions?

A: 

What if you put it in parenthesis?

To have http:// start again on the url is an invalid address.

http://www.mydomain.com/Puzzle/ContinuePuzzle/(http://mypuzzlingdomain.com/?a4)

Or perhaps braces may work also.

Brettski
A: 

UrlEncode it but pass it as a get variable...?

E.g. http://www.mydomain.com/Puzzle/ContinuePuzzle?url=http%3a%2f%2fmypuzzlingdomain.com%2f%3fa4

Charlino
I've tried that. It doesn't work.
Micah
I did a test and I was able to use a get variable. If needed, I can add the code to my answer.
Dale Ragan
+2  A: 

I have a suspicion having two scheme declarations in the URL is causing the default route handler to throw the 400 response.

As a work around, I would just send the URL without the scheme (i.e. http://). I tested this scenario without any problems:

http://www.mydomain.com/Puzzle/ContinuePuzzle/www.domain.com/nextpuzzle

Using this route:

routes.MapRoute("Puzzle", "Puzzle/ContinuePuzzle/{*url}", new {controller = "Puzzle", action = "ContinuePuzzle", url = ""});

If you have to have the scheme, then use a querystring parameter like Charlino suggested.

Dale Ragan