Config Routing to functions other than the default ones

In my controller class I implement my interface, the controller class is a subclass of ApiController

I have a method for my API called Read. I would like the default Get() to call Read().

Without having to do

Get()
{
    Read();
}

Also I dont want to do /api/{controller}/{action}/{id}

I'd like /api/{controller}/{id} to route to the Read() method instead of Get()

The question is: Lets say I have a Controller thats called Devices. When a GET request to /api/Devices/ heppens I want it to call my specific method rather than the Get() method of the APIController.

Answers


You can use ASP.NET Web API Attribute Routing! (http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2)

[HttpGet]
[Route("api/MyController/MyAction")]
public string Read() {
   return "You issued a GET request to the Read method";
}

You can do whatever you want with the route, just make sure you map the routes in the WebApiConfig like this: config.MapHttpAttributeRoutes(); (see the article for more info on that).


Need Your Help

Sanitising include file before having them executed using a whitelist

php include sanitization whitelist

Is it possible to sanitise an include before it is executed to make sure that it exists on the server?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.