tags:

views:

440

answers:

3

Hello, I need to pass a full website url to my controller action, like this:

http://myweb/controller/action/http://blabla.com/dir2

how to create a new route for passing this parameter to action?

+3  A: 
routes.MapRoute("Name", "{controller}/{action}/{*url}");

Additional Info:

Koistya Navin
thanks, but with {*url} , I cannot still pass the "http://" for the parameter, HTTP Error 400 - Bad Request. is raised. or with :portnumber at the end of url, same error
mohamadreza
try this <a href="./controller/action/<%= HttpUtility.UrlEncode("http://www.riaguy.com") =%>">Test</a>
Koistya Navin
thats right, but the parameter is passed from outside of application, I want it to be like restful api which add this url to db, wonder if it is possible to have this format just by typing(without using any server side or client side decode functions) or not
mohamadreza
The problem is not in {*url}, ASP.NET MVC chast can't accept http:// in URL which wasn't encoded.. you can try overcome this by writing custom Route programmatically..
Koistya Navin
public class YouCustomRoute : RouteBase { ... }
Koistya Navin
also take a look at this article: http://stephenwalther.com/blog/archive/2008/03/18/asp-net-mvc-in-depth-the-life-of-an-asp-net-mvc-request.aspx
Koistya Navin
+1  A: 

Pass it as a parameter.

<%= Html.ActionLink( "Link", 
                     "MyAction",
                     "MyController",
                     new { url = "http://blah.com/blah" },
                     null ) %>

Should produce a link that looks like:

<a href='/MyController/MyAction?url=http://blah.com/blah'&gt;Link&lt;/a&gt;

Your action would look like:

public ActionResult MyAction( string url )
{
   ...
}
tvanfosson
A: 

also remember to encode the url parameter.

Mike Geise