The code sample for Web API Routing as given below.
namespace demoRoutes { public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApiWithAction", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } } }
The code sample for MVC 5 Routing as given below.
namespace demoRoutes { 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 } ); } } }
The Attribute based routing in MVC 5 as given below.
[RoutePrefix("API/Alert")] public class AlertController : ApiController { Mapper mapper = new Mapper(); /// This method is used to GetReceipe collection. [Route("GetReceipe")] public IEnumerableGetReceipe() { DALReceipe objDalReceipe = new DALReceipe(); ICollection resceipe = mapper.MapDALReceipes2BAL(objDalReceipe.getReceipe()); return resceipe; } }