Attribute routing in ASP NET Web API 2

kudvenkat
kudvenkat
126.6 هزار بار بازدید - 8 سال پیش - For the example code used
For the example code used in the demo, please refer to the text article of this video.
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
@aarvikitchen5572

Slides
http://csharp-video-tutorials.blogspo...

All ASP .NET Web API Text Articles and Slides
http://csharp-video-tutorials.blogspo...

All ASP .NET Web API Videos
ASP.NET Web API tutorial for beginners

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...

All Dot Net and SQL Server Tutorials in Arabic
kudvenkatarabic

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.
8 سال پیش در تاریخ 1395/11/26 منتشر شده است.
126,618 بـار بازدید شده
... بیشتر