Attribute routing in ASP NET Web API 2 HD
For the example code used in the demo, please refer to the text article of this video. http://csharp-video-tutorials.blogspot.com/2017/02/attribute-routing-in-aspnet-web-api-2.html Slides http://csharp-video-tutorials.blogspot.com/2017/02/attribute-routing-in-aspnet-web-api-2_14.html All ASP .NET Web API Text Articles and Slides http://csharp-video-tutorials.blogspot.com/2016/09/aspnet-web-api-tutorial-for-beginners.html All ASP .NET Web API Videos https://www.youtube.com/playlist?list=PL6n9fhu94yhW7yoUOGNOfHurUE6bpOO2b All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists In this video we will discuss Attribute Routing introduced in ASP.NET Web API 2. Let us understand attribute routing with an example What is Attribute Routing Using the [Route] attribute to define routes is called Attribute Routing What are the advantages of using Attribute Routing Attribute routing gives us more control over the URIs than convention-based routing. Creating URI patterns like hierarchies of resources (For example, students have courses, Departments have employees) is very difficult with convention-based routing. With attribute routing all you have to do is use the [Route] attribute as shown below. [Route("api/students/{id}/courses")] How to enable Attribute Routing In ASP.NET Web API 2, Attribute Routing is enabled by default. The following line of code in WebApiConfig.cs file enables Attribute Routing. config.MapHttpAttributeRoutes(); Can we use both Attribute Routing and Convention-based routing in a single Web API project Yes, both the routing mechanisms can be combined in a single Web API project. The controller action methods that have the [Route] attribute uses Attribute Routing, and the others without [Route] attribute uses Convention-based routing.