1

Why does the WebApi controller have to end in the word Controller to work in a web forms environment?Microsoft demo referenced this post

Note: Make sure the name ends in “Controller” and not “Controller1” or similar.

1
  • Lets assume that I dont want it called XXXController, how do i add a correct route iny in Application_start method Commented Apr 15, 2013 at 18:58

1 Answer 1

2

Because it is part of Microsoft's strategy (many software companies are following this paradigm) of Convention Over Configuration for their newer technologies.

Wikipedia entry:

Convention over configuration (also known as coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility. The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called “sales” by default. It is only if one deviates from this convention, such as calling the table “products_sold”, that one needs to write code regarding these names. When the convention implemented by the tool matches the desired behavior, it behaves as expected without having to write configuration files. Only when the desired behavior deviates from the implemented convention is explicit configuration required.

Sign up to request clarification or add additional context in comments.

3 Comments

Lets assume that I dont want it called XXXController, how do i add a correct route iny in my Application_start method
@gh9: I don't know, I haven't tried. I would recommend sticking to convention on this however. Trying to force out of COC might give you serious headaches.
You can change the convention by replacing the default implementation of IHttpControllerSelector, but that's orthogonal to whether you are using Web Forms. See asp.net/web-api/overview/web-api-routing-and-actions/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.