5

I m working on Web API project, and it is using WebApiConfig.cs file to defined routs for Web API.

Web API fold RouteConfig.cs file. I have googled and they say RouteConfig.cs is for MVC routing. It is actually a confusing statement. Can you please guide why WebAPI has RouteConfig.cs file ? Why would one need MVC routing in Web API ? What function it will do ?

Thanks for your help and guidance.

user576510
  • 211
  • 3
  • 6

1 Answers1

9

The RouteConfig.cs file isn't required for Web API. It is included by default in new Web API projects because that template also includes an MVC webpage (for the index page that appears when you open the project in a browser).

If you delete both the RouteConfig.cs and the HomeController.cs file (as well as modify Global.asax.cs to not call RouteConfig.RegisterRoutes()), then your project will still compile and the API controllers will still work fine, you will just be missing a pretty homepage.

Note also that MVC Areas have their own MVC routing and do not use the global MVC routing, which is why the /Help page still works even when RouteConfig.cs has been removed.

Jack Scott
  • 1,374
  • 9
  • 9
  • thanks, awesome explanation. Just a silly question please, by "MVC Areas" what are you referring exactly ? Can you please guide. – user576510 Oct 27 '14 at 22:43
  • 1
    @user576510 [This page](http://msdn.microsoft.com/en-us/library/ee671793%28VS.100%29.aspx) has a good guide to MVC Areas, including this good description: _To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas. Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas)._ – Jack Scott Oct 27 '14 at 22:49