Tushar Vasudev Tushar Vasudev - 13 days ago 6
ASP.NET (C#) Question

How to define custom api routes in Azure Mobile Service when using .NET as Back end?

Tried both Table Controller and Custom Controller but not able to define two functions accepting the same parameters with same http method. For example when declaring

public Person GetMemberDetails(int id)
{
// Some Code
return person;
}

public Person GetMemberAddress(int id)
{
// Some Code
return person;
}


as both functions are requesting using GET and both have same input after building the project i am not able to use either of them. When i delete one or modifies one to use any other requesting method i am able to request from.

http://<azure-mobile-service-name>/Person/{id}


Is there any way to declare two functions with same signature and same method of request?

Answer

You need to use the Route attribute, eg:

 [Route("api/getdetails")]
public Person GetMemberDetails(int id)
{
   // Some Code
   return person;
}
[Route("api/getaddress")]
public Person GetMemberAddress(int id)
{
   // Some Code
   return person;
}

Or search for "attribute routing" if you want the id in the route