Using WebApi RoutePrefix attribute on a base controller
Support for inheritance has been enabled in Web API 2.2 release...You can take a look at an example in the following Release Notes:
http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-22#ARI
Marc Costello
Web focused software developer. I'm very passionate about many languages, technologies and software principals - I enjoy putting myself outside of my comfort zone to learn new approaches to problem solving in software. I genuinely believe as developers we should learn as many languages, patterns and paradigms as possible to expand knowledge.
Updated on June 06, 2022Comments
-
Marc Costello almost 2 years
I would like all controllers which inherit from
AdminBaseApiController
to be prefixed with 'admin'.This works fine of course:
[RoutePrefix("admin")] public class ToggleController : AdminBaseApiController { [Route("toggle")] public HttpResponseMessage Get() { } }
However when I move the
RoutePrefix("admin")
out of theToggleController
and into theAdminBaseApiController
(where I want it) - The route fails and I get a 404.Am I looking at this all wrong? Thanks in advance!