RouteCollection.Add(String, RouteBase) Method


Adds a route to the end of the RouteCollection object and assigns the specified name to the route.

 void Add(System::String ^ name, System::Web::Routing::RouteBase ^ item);
public void Add (string name, System.Web.Routing.RouteBase item);
override this.Add : string * System.Web.Routing.RouteBase -> unit
Public Sub Add (name As String, item As RouteBase)



The value that identifies the route. The value can be null or an empty string.


The route to add to the end of the collection.


item is null.

name is already used in the collection.


The following example shows how to add a route to a RouteCollection object and assign a name to the route.

void Application_Start(object sender, EventArgs e) 
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub


The Add method enables you to define a name for a route when you add it to the route collection. By defining a name for the route, you can specify a particular route to use when you use routing to construct a URL. Specifying a particular route is important when more than one route matches the values that you pass to the GetVirtualPath method. If you do not specify a named route, ASP.NET routing will use the first route in the collection that matches the values. For more information, see How to: Construct URLs from Routes.

A name can be used only one time in the RouteCollection object.

If you do not have to specify a name for the route, you can add the route by calling the Add method.

Use the GetReadLock method and the GetWriteLock method to make sure that you interact with the collection without conflicts from other processes.

Applies to

See also