How to add custom routes in custom mobile controller

Category: azure mobile


VenkateshSrini_CHN on Sat, 19 Mar 2016 14:26:56


I'm creating custom mobile controller. The code is as below



public mycontroller:ApiCOntroller



I want to use route attribute to do custom routing. But this does not seem to work. Please help

Thanks and regards


Venkatesh. S|MCTS(WCF, ADO.NET 3.5)|eMail:


Robert Bermejo on Sat, 19 Mar 2016 16:10:30


Attribute route adds in method, not in controllers

[MobileAppController] public mycontroller:ApiCOntroller { [Route("/api/My/MyService/Method")] public async Task Method() {

//Your Code

} }

You need configre mapHttpAttributeRoutes:

HttpConfiguration config = new HttpConfiguration();

Don't forget add Microsoft.AspNet.WebApi.WebHost NuGet package.


VenkateshSrini_CHN on Sun, 20 Mar 2016 06:47:51


It is working now. But could you please tell me why the same is not getting displayed in Swagger documentation. Please help me in resolving this

Robert Bermejo on Sun, 20 Mar 2016 07:04:42


I don't know, i supposed because swagger no depends from language, and this behaviour is to .Net WebApi.

VenkateshSrini_CHN on Sun, 20 Mar 2016 13:25:28

Hi Robert,

I have found the solution for the same. After you make the customization to the route, we need to stop the running project, kill the IIS express or re-deploy in case you are using local IIS. Alternatively you can just stop the process, close the visual studio 2015 and re-open the same. This will re-load from start. The reason is that the routes are all loaded in start up class which get loaded when the application re-start. In Azure it should reflect automatically but then if that does not happen then stop and star the site once.

Thanks and regards