0

After upgrading from MVC4 with AttributeRouting.net to MVC5 with MVC5's attribute routing, I can't seem to get the default route working so that http://server defaults to http://server/home/index . Browsing directly to /home/ or /home/index works fine.

For route config, I have this:

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapMvcAttributeRoutes();
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

The HomeController declaration looks like this:

// Controller
[RoutePrefix("home")]
public class HomeController : MvcControllerBase
....
    // Action
    [HttpGet, Route, Route("index")]
    public ActionResult Index()
    {
   .....

I'm not sure where else to check. I've commented out everything in Global and disabled all WebActivator-activated items.

And ideas? The response is 404 with no exception being thrown.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Ken
  • 834
  • 9
  • 25

1 Answers1

0

Ah.. got it!

Based on Kiran's answer to : Specify default controller/action route in WebAPI using AttributeRouting

I changed HomeController to:

// Controller
public class HomeController : MvcControllerBase
....
    // Action
    [HttpGet, Route, Route("home"), Route("home/index")]
    public ActionResult Index()
    {
....

And I got rid of the MVC Config default.

Community
  • 1
  • 1
Ken
  • 834
  • 9
  • 25