6

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?

2 Answers 2

8
routes.MapRoute("Name", "{controller}/{action}/{*url}");

Additional Info:

Sign up to request clarification or add additional context in comments.

6 Comments

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
try this <a href="./controller/action/<%= HttpUtility.UrlEncode("riaguy.com") =%>">Test</a>
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
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..
public class YouCustomRoute : RouteBase { ... }
|
6

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'>Link</a>

Your action would look like:

public ActionResult MyAction( string url )
{
   ...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.