If I apply [Route(Name = "WhatEver")] to action, which I use as Default site route, I get HTTP 404 when accesing site root.
For example:
- Create new sample MVC project.
Add attributes routing:
// file: App_Start/RouteConfig.cs public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); // Add this line routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } }
Add routing attributes
[RoutePrefix("Zome")] public class HomeController : Controller { [Route(Name = "Zndex")] public ActionResult Index() { return View(); } ... }
And now, when you start your project for debuging, you will have HTTP Error 404. How should I use attribute routing with default route mapping?
See Question&Answers more detail:os