Understanding Routing in ASP.NET MVC – PART 1

Introduction

In this article we are going to discuss about the basic ASP.NET MVC Routing, how it works and difference between ASP.NET web Form request and ASP.NET MVC request.

What is Routing?

Routing is set of rules/pattern matching system that monitors the incoming request from the browser and set matched location to process further.

The Routing engine uses the virtual route table which helps to finding the matching pattern for the incoming request (URL) from the browser.

Request handle in webform and ASP.NET MVC :

In ASP.NET Web forms, the request from the browser is mapped to the page which is physically present in our application/website directory like Home.aspx, AboutUs.aspx.

But in ASP.NET MVC, the request needs to be mapped to a controller and action. In ASP.NET MVC, we don’t have concept of physical file(like aspx).

Difference between In ASP.NET Web Form and  ASP.NET MVC request?

In MVC, we are having the controller and action methods. Each controller has multiple action methods.
Routing takes care of the mapping strategy for mapping request URLs to the controllers and action methods. we know already that .aspx will be available in the ASP.NET Web form request as shown below. But in MVC we dont have any extension like this because it won’t have physical file location (one controller have multiple action).

ASP.NET Web forms request : http://dotnet-helpers.com/MVCRoute/Route.aspx

ASP.NET MVC request : http://dotnet-helpers.com/MVCRoute/Route

MVCRoute is a Controller
Route  is an Action

From above, .aspx is physical file which is present in the application directory so no separate mechanism for handling the request. In ASP.NET MVC, there is no physical file for route, it contains controller and the action.

Flow of Routing :

Routemapping-dotnet-helpers.com1

From above flow, the request is handled by routing. First route engine parses the  incoming URL and  match the request with virtual route table. If request match with the pattern present in the route table then it will redirect to the particular controller and action. If match not found in the route pattern then it will show the 404 error.

Here we have discussed the basics of the routing concept. In upcoming article we will discuss more in depth about routing. Happy coding.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s