I have a default routing so if I go to http://www.domain.com/app/ it’s, for example, the HomeController. I have another action on the control, e.g. helloworld but if I go to http://www.domain.com/app/helloworld it fails with a 404 (expecting helloworld controller no doubt).
How can I can non-default actions on my default controller OR how can I map the url /app/helloworld to the helloworld action. My routing looks like this:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute( //this fails with same 404 like it does when it's ommitted
"Hello", // Route name
"app/helloworld", // URL with parameters
new { controller = "Home", action = "HellowWorld", id = UrlParameter.Optional } // Parameter defaults
);
Basically I need:
/app/ => Controller = Home, Action = Index
/app/helloworld => Controller = Home, Action = HelloWorld,
not Controller = HelloWorld, Action – Index
/app/other => Controller = Other, Action = Index
Replace the 2
routesin your Global file with this:Then verify your
HomeControllercontains:What this is doing is that
yoursite.com/app/ANYCONTROLLER/ANYACTIONwill route to the controller and action (as long as they exist,) and the defaultnew { controller = "Home", action = "Index"means that if someone goes toyoursite.com/app/it will automatically route toyoursite.com/app/Home/Index.If this doesn’t work try removing the
app/so it will look like:What you had looks like you were trying to route
yoursite.com/Home/Indexand the second route was phrased wrong, I’m not sure what it would do but instead of"app/helloworldit should have looked like"app/HelloWorld/{action}/{id}"thennew { controller = "Home", action = "HellowWorld"would work. So that if someone went toyoursite.com/appit would automatically displayyoursite.com/app/Home/HelloWorld. Hope that helps clear some things up.This is the answer you want
For some reason you don’t want to create a new controller for the hello world section, your
RegisterRoutesin theGlobalfile should look like this:Although I would not recommend going about it this way.