Skip to content

Instantly share code, notes, and snippets.

@weiland
Created August 7, 2014 13:34
Show Gist options
  • Save weiland/8c9e262fc002c919b120 to your computer and use it in GitHub Desktop.
Save weiland/8c9e262fc002c919b120 to your computer and use it in GitHub Desktop.
Supports building a REST API with ASP.net MVC 5
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// add this block \o/
routes.MapRoute(
name: "single",
url: "{controller}/{id}",
defaults: new { controller = "Home", action = "Index" },
constraints: new { id = @"^[0-9]+$" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment