I want to create a simple blog engine. For trendy and clean URLs, I would like to use the routing mechanism implemented in MVC4.
I added the following lines to RouteConfig.cs:
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( name: "ArticleList", url: "Articles/{category}/{page}", defaults: new { controller = "Articles", category = UrlParameter.Optional, page = 1 }); } }
And if I write to the web browser url:
http:
I want to go to this controller:
public class ArticlesController : ControllerBase<IHomeService> { public ActionResult Index(string category, int page = 0) { return View("~/Views/Article/Articles.cshtml"); } }
with the parameters category = "SomeCategory" and page = 1.
All I get is a Server Error in the application '/' Resource not found.
What's wrong?
source share