简体   繁体   中英

WebApi2 Attribute Routing doesn't work unless controller classes are named in a specific manner

I was debugging an issue with attribute routing giving 404s for known-good routes. Well, known-good to me, but they weren't being picked up by the framework. I was grouping my controllers/models into logical units, eg:

Auth
    Models
        Model1
        Model2
    Controller

So my "AuthController" is named MyApi.Auth.Controller instead of, for instance, MyApi.Auth.AuthController .

My routes were not being picked up until I renamed my controller, adding anything before it, eg zzController . This makes me think there's a bug in attribute routing, or am I missing something?

ASP is convention over configuration. Whether they add features that go away from that or not, always stick to the convention when it comes to Controllers and Views. It'll make maintenance so much easier (plus in the next version of MVC, there is no more ApiController, everything is just a Controller).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM