Having dash or url on MapRoute

53 Views Asked by At

I try to get url from users and provide MapRoute like this:

routes.MapRoute("checkUrl", "tools/{id}", new { controller = "Home", action = "tools" }, new { });

On this case, it's works for this url: "/tools/www.domain.com/"

But how could I manage such a url: "/tools/www.domain.com/view/child/child/?id=4"

Route can't find such a address.

2

There are 2 best solutions below

0
On

You can use catchall in nexy maproute or use it instead of id.

0
On

You can not directly pass the URL as a parameter. You have to pass in a query string.

Before passing the URL you have to encode the URL.

Refer my URL for pass "/tools/www.domain.com/view/child/child/?id=4" in below.

http://localhost:54964/Home/Index?id=www.domain.com%2Fview%2Fchild%2Fchild%2F%3Fid%3D4

I getting value in the id parameter in the method.

public ActionResult Index(string id)
{
            return View();
}