What happens if routing is not there in mvc ? [Resolved]

Posted by Kasani007 under ASP.NET MVC on 7/3/2014 | Points: 10 | Views : 736 | Status : [Member] | Replies : 4
What Happens if routing is not there in MVC ? What is the Importance of Routing in MVC ?




Responses

Posted by: Goud.Kv on: 7/4/2014 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
Hi,

1. Without using Routing in an ASP.NET MVC application, the incoming browser request should be mapped to a physical file.The thing is that if the file is not there, then you will get a page not found error.
2. By using Routing, it will make use of URLs where there is no need of mapping to specific files in a web site.
This is because, for the URL, there is no need to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.

MVC gives you great control over how URLs are mapped to your controllers. It gives you the ability to define your URLs in a human readable SEO (Search Engine Optimization) friendly fashion, to remap old URLs to new functionality and side-by-side utilizes classic ASP.NET sites inside of MVC. It also results in hiding what kind of page a user is calling and what environment we are working in. Most of the new websites are following this and it is important to understand that routing is not URL rewriting as routing will have customizations and many attachments towards request/response.

When we create any type of MVC application by default Global.asax file is created because ASP.NET implements MVC using this global application class mainly. Routes defined in the Global.asax.cs file of our MVC web application. In this global.asax file most important element relative to our work is RegisterRoutes method. By default, there is only one route defined in the RegisterRoutes method that looks like the code below.

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");
routes.MapRoute (
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}


Thanks & Regards,
Krishna

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 7/4/2014 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
There are many importance of routing and below are few

1. Routing helps us to make the url user friendly, SEO friendly, easily readable and understandable.
2. In ASP.NET MVC routing instruct the framework to call which action method of which controller.
3. It also helps us to make a custom url for a content that might not be physically on the machine.

There might be many more but this is what came to my mind now.

Thanks



Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 7/4/2014 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Good one Goud.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Goud.Kv on: 7/4/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Thank you sir,

Thanks & Regards,
Krishna

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response