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 utilize classic ASP.NET sites inside of MVC3. It also results in hiding what kind of page 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 customization's and many attachments towards request/response.
When we create any type of MVC application by default GLOBAL.ASAX file is created becoz ASP.NET implements MVC using this global application class mainly. Routes defined in the Global.asax.cs file of our MVC3 web application/site. 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 line below.
Custom MVC Routes
In a ASP.NET site for a magazine, you might have a URL that looks like www.internet.com/ViewArticle.aspx?id=123. This URL passes the ID number of the article to view, but the URL itself doesn't describe the content in any human readable way
If the URL instead was www.internet.com/MVC_Routing/123 a human-or a web crawler-could read that and know that the article is about MVC_ Routing
Defination of Routing :
It is a program or process which is responsible to map the given URL to a controller and its action method.
Explanation: Is the process where user will type the URL which will be converted to handlers and there will be the mediator who will take this Uri and map to the server.
Now product ID for what(tv,mobile,etc)
In mvc we can define as
Initially routing was provided in MVC today available in entire .Net.
This was introduced because of the way ASP.NET MVC works rather, than being handled by a page handler each request needs to be routed to a specific action method of a specific controller Class.
Routing provides "clean" URLs
URL is mapped to a route handler
Extra level of indirection
Handlers can be changed without impacting URL
URL can be changed without impacting handler
URL Example Example http://www.mysite.com/Home/ProductList
Note
Catch-all route
Put this route last
It will match any URL which has not matched any other route
============================
No comments:
Post a Comment
Thank you for visiting my blog