Skip to Main Content
ASP.NET 4 24-Hour Trainer
book

ASP.NET 4 24-Hour Trainer

by Toi B. Wright
July 2010
Beginner content levelBeginner
552 pages
10h 14m
English
Wrox
Content preview from ASP.NET 4 24-Hour Trainer

Chapter 15A. URL Routing in Web Forms

URL Routing was first introduced in the ASP.NET MVC framework and was later added to the ASP.NET Web Forms framework. In this lesson I show you how to enable and use routing in an ASP.NET Web Forms framework web application.

Only the MVC templates and the ASP.NET Dynamic Data templates have routing enabled by default. The ASP.NET Web Application template that I have been using in all of my examples does not have routing enabled by default. These are the four steps that must be completed to add routing to a web application that was created using a template that does not have routing enabled:

  1. Add a reference to the System.Web.Routing assembly (see Figure 15A-1).

    FIGURE 15A-1

    Figure 15A.1. FIGURE 15A-1

  2. Add the following using statement to the Global.asax.cs file:

    using System.Web.Routing;
  3. Add the following RegisterRoutes method to the Global.asax.cs file:

    void RegisterRoutes(RouteCollection routes)
    {
    
    )
  4. Add the following line to the Application_Start method in the Global.asax.cs file:

    RegisterRoutes(RouteTable.Routes);

Now you can start using routing in your ASP.NET Web Forms application.

ASP.NET Web Forms uses the MapPageRoute method of the RouteCollection class to define new routes. The MapPageRoute method can include the following parameters:

  • routeName — This is a string representing the name of the route.

  • routeUrl — This is a string that contains the URL pattern for the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 4 24-Hour Trainer

ASP.NET 4 24-Hour Trainer

Toi B. Wright
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470596913Purchase bookExamplesErrata