Route.Url Property

Definition

Gets or sets the URL pattern for the route.

public:
 property System::String ^ Url { System::String ^ get(); void set(System::String ^ value); };
public string Url { get; set; }
member this.Url : string with get, set
Public Property Url As String

Property Value

The pattern for matching the route to a URL.

Exceptions

Any of the following:

  • The value starts with ~ or /.

  • The value contains a ? character.

  • The catch-all parameter is not last.

URL segments are not separated by a delimiter or a literal constant.

Examples

The following example shows how to set the Url property in the class constructor. The pattern contains the literal value "Category" for the first segment and URL parameters for the next two segments.

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Add(new Route
    (
         "Category/{action}/{categoryName}"
         , new CategoryRouteHandler()
    ));
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RegisterRoutes(RouteTable.Routes)
End Sub

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    Dim urlPattern As String
    Dim categoryRoute As Route
    
    urlPattern = "Category/{action}/{categoryName}"
    
    categoryRoute = New Route(urlPattern, New CategoryRouteHandler)
    
    routes.Add(categoryRoute)
End Sub

Remarks

When you assign a value to the Url property, the / character is interpreted as a delimiter when the URL is parsed. Use braces ({}) to define a variable that is referred to as a URL parameter. The value from the matching segment in the URL is assigned to the URL parameter. Any values in the Url property that are not enclosed in braces are treated as literal constants.

The ? character is not allowed in the Url property. Each URL segment must be separated by either a delimiter or literal constant. You can use {{ or }} as escape characters for a brace character.

Applies to

See also