Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am working on a MVC 4 project that will serve as an API layer of a larger appl

ID: 651379 • Letter: I

Question

I am working on a MVC 4 project that will serve as an API layer of a larger application.

The developers that came before me set up separate Areas to separate different API requests (i.e Search, Customers, Products, and so forth).

I am noticing that each Area has separate Area registration classes that define routes for that area. However, the routes defined are not area-specific (i.e. {controller}/{action}/{id} might be defined redundantly in a couple of areas).

My instinct would be to move all of these route definitions to a common place like the Global.asax to avoid redundancy and collisions, but I am not sure if I am correct about that.

Explanation / Answer

Your route organization will depend entirely on what your goals are.

Some routes are organized in such a way that the resulting URLs increase search engine optimization. Others are designed for readability, or to be as short as possible. Still others are arranged hierarchically, based on the folder structure of the application.

In short, there is no "one, true way." This is why routing exists in the first place. Were there only a single right way to arrange your URLs, you wouldn't need the "patch-bay" mechanism that routing provides.

If your question is where to put the routes, you should put them where it makes most sense to you. If the areas function independently and have different routing rules, it probably makes sense for each area to have its own routes. If, on the other hand, all the areas use the same routing scheme, it probably makes sense to keep a set of global rules.

It is my understanding that ASP.NET MVC checks the area routing rules first, so if you have some rules that are specific to a certain area, you can put those rules in the area, and if none of them match, the routing engine will fall back to the global routes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote