Click here to Skip to main content
15,881,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,
I have one issue with WebApi routing. Please find the code snippet below-

C#
config.Routes.MapHttpRoute(
               name: "reportsApi",
               routeTemplate: "api/{controller}/list/",
               defaults: new { reports = RouteParameter.Optional  }
           );


Earlier it was working just fine and there is no change in the code of report module and it stopped working after the deployment of another version. When i remove '/list' from 'https://whatever.com/api/report/list it works fine as expected.

Any idea? Any help will be highly appreciated.

Thanks
Amod
Posted
Updated 14-Jun-15 19:26pm
v2

Your routing isn't quite correct, largely because you're referencing a parameter that isn't there. If you include a default option, you should also have a placeholder in the template to match it:

For instance (based on the URL in your question):
C#
config.Routes.MapHttpRoute(
               name: "reportsApi",
               routeTemplate: "api/{controller}/{reports}/list/",
               defaults: new { reports = RouteParameter.Optional  }
           );


Looking at it, I'm not sure what the 'list' is doing for you in that particular route, but based on your URL I can only assume it's either ReportController.List(), or an acceptable id parameter for ReportController.Get(). My supposition is that it's using the default route when you change the address.
 
Share this answer
 
Hi
I agree with Nathan, in your routing you have mentioned reports as defaults but then why is not seen in the route template..
C#
config.Routes.MapHttpRoute(
               name: "reportsApi",
               routeTemplate: "api/{controller}/list/",
               defaults: new { reports = RouteParameter.Optional  }
           );


Try adding reports to route template as below..

C#
config.Routes.MapHttpRoute(
               name: "reportsApi",
               routeTemplate: "api/{controller}/{reports}/list/",
               defaults: new { reports = RouteParameter.Optional  }
           );


Hope this helps..
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900