Chapter 7. Routing
Now that you have completed your journey exploring the three parts of an MVC application, it's time for you to learn about the places where a request meets the application: the routing engine.
In this chapter, you learn:
What routing is
How to define routing rules
How to debug routes
Life before Routing
In a typical WebForm-based Web application, the user types a URL in the address bar of his browser, and then the request is sent to the server. The server takes the URL, looks at the file system for a file that is located in the folder and with the name specified in the URL, executes the code-behind that is mapped to the file, and finally sends the response back to the user. To display the listing of all the books in the category ASP.NET, you would type http://example.com/catalog/booklisting.aspx?id=345
. But this URL is not a very good one. For the user it's not obvious that 345 is the ID of the category of books on ASP.NET.
Speaking of search engine optimization (SEO), because all categories are retrieved using the same path (catalog/booklisting.aspx), search engines might not do a very good job of indexing the bookstore catalog. A URL like http://example.com/catalog/ASPNET
would have been both more SEO-friendly and easier to remember and understand for the end user, who could just change the last part to ASPNETMVC
to get all the books on ASP.NET MVC.
Over the years, many solutions have been implemented to make WebForm URLs more user- and SEO-friendly, the most notable ...
Get Beginning ASP.NET MVC 1.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.