Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Routing for a Single Controller Site

I'm trying to create a simple site. Basically it has one Controller Home controller.

This controller has an action Index takes a string as argument (which is a directory) and uses that 'directory' to do its work.

I can't work out how to create a generic catch all route that will send every URL to this one Action.

Any URL combination could exist, and anything beyond the domain name should be the string.

http://<domain>/2008
http://<domain>/2008/09
http://<domain>/2008/09/Fred

Does anyone know how to do this? It would also be alright if all the values are passed as a list.

Is there a better way of doing this?

like image 887
Jordan Avatar asked Dec 23 '22 08:12

Jordan


1 Answers

Try this :

routes.MapRoute(
        "Default", "{*path}",
        new { controller = "Home", action = "Index" } 
    );

And the controller :

public class HomeController : Controller {
    public ActionResult Index(string path) {
        return View();
    }
}
like image 171
Çağdaş Tekin Avatar answered Dec 29 '22 09:12

Çağdaş Tekin