Important of RouteConfig.cs in MVC


Lets see important of RoutConfig.cs file in MVC Application.

if you look at your MVC application, you will find RouteConfig.cs file in App_start folder.

in RouteConfig.cs file you will find the method name RegisterRoutes. This method is use to add routing information in RouteCollection.

This RegisterRoutes method is call from Global.asax file. 

    RouteConfig.cs file


RouteConfig.cs is very important file in MVC Application.

Here we do mapping  user friendly URL ( for end user) with controller name and action.

route.MapRoute add the routing information in RouteCollection.
In Maproute first argument is name. which must be unique name.
Second argument is URL format. 
Third argument is Controller, Action and Argument.

Now lets take example of I am creating Ketan Controller and Ketan View. We will give user friendly URL to end user.

In MVC Application you do not set start page by clicking on web page.  
From RouteConfig.cs file you can do it.
See below screen shot.

Now suppose you want to saw this StartPage action when application is default loaded.

Please note here you have to keep empty URL so it will take default page and route default page to  StartPage action of ketan controller.

There are much more we will do with RouteConfig file. I will discuss it later.

Posted in Labels: |


Post a Comment