Name Collisions with Asp.Net Webapi and How to Avoid

Posted by Peter Kellner on February 04, 2015 · 1 min read

I love the simplicity of using ASP.NET WebAPI for building simple web rest services.  No special calls to create JSON, simple REST conventions implemented with the methods GET,POST,PUT and DELETE and very straight forward interfaces.

The thing that annoys me is the naming convention.  In my case, I’ve create a folder /rest on my web server and I put all my WebAPI controllers there.  An example of a controller looks as follows:

public class FaqController : ApiController
        public HttpResponseMessage Get(int? id = null, string urlPart = null, int? arrayonly = null)


The problems comes up when you decide you want to have a different FAQ controller for different parts of the web site.  The obvious solution is to drop the REST services into sub directories.  Unfortunately, since the class name above does not change, you have conflict.  I’m guessing there is some attribute to solve this but it just feels clunky to me.