asp.net webapi 2 attribute routing not working

后端 未结 9 1931
再見小時候
再見小時候 2020-12-23 17:02

I have visual studio 2012 installed with mvc4 using .net framework 4.5. Now I want to use webapi2 with attribute writing and i want my hlep page show all the endpoints prope

相关标签:
9条回答
  • 2020-12-23 17:39

    Make sure you don't have two controllers with the same name! I was moving some controllers from one assembly I was throwing away into the website... whilst the website no longer had references to the old assembly other assemblies did which meant it was copied in to the WebSite bin folder. The route discovery process then seemed to fail silently when it came across two occurrences of the same controller!

    0 讨论(0)
  • 2020-12-23 17:40

    This question already has a selected answer. But I had a different solution for myself and think it would be helpful to reply if the selected answer doesn't help.

    For me it was a silly mistake. I had two controllers but only one was working. The solutions was that my controller class was named improperly!

    My working controller-

    public class FooController : ApiController { }
    

    My non-working controller-

    public class BarControllers : ApiController { }
    

    Be sure your controller class ends in Controller. The trailing s got me!

    0 讨论(0)
  • 2020-12-23 17:41

    Based on your information, it looks like you are not calling the httpConfig.MapHttpAttributeRoutes() (Make sure to call this before any traditional routing registrations)

    Since you haven't called MapHttpAttributeRoutes, your request seems to be matching a traditional route, for example, like api/{controller}. This will not work because routes matching traditional routes will never see controllers/actions decorated with attribute routes.

    0 讨论(0)
提交回复
热议问题