Text version of the video
Slides
All ASP .NET Web API Text Articles and Slides
All ASP .NET Web API Videos
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
To generate links in ASP.NET Web API using route names
1. Set a name for the route using the Name property of the [Route] attribute
[Route(“{id:int}”, Name = “GetStudentById”)]
public Student Get(int id)
{
return students.FirstOrDefault(s =] s.Id == id);
}
2. Use the name of the route to generate the link
public HttpResponseMessage Post(Student student)
{
students.Add(student);
var response = Request.CreateResponse(HttpStatusCode.Created);
response.Headers.Location = new Uri(Url.Link(“GetStudentById”, new { id = student.Id }));
return response;
}