Route.DataTokens Route.DataTokens Route.DataTokens Route.DataTokens Property

Definición

Obtiene o establece los valores personalizados que se pasan al controlador de ruta pero que no se usan para determinar si la ruta coincide con un modelo de dirección URL.Gets or sets custom values that are passed to the route handler, but which are not used to determine whether the route matches a URL pattern.

public:
 property System::Web::Routing::RouteValueDictionary ^ DataTokens { System::Web::Routing::RouteValueDictionary ^ get(); void set(System::Web::Routing::RouteValueDictionary ^ value); };
public System.Web.Routing.RouteValueDictionary DataTokens { get; set; }
member this.DataTokens : System.Web.Routing.RouteValueDictionary with get, set
Public Property DataTokens As RouteValueDictionary

Valor de propiedad

Objeto que contiene los valores personalizados.An object that contains custom values.

Ejemplos

En el ejemplo siguiente se muestra cómo crear Route un objeto y establecer Constraintslas DataTokenspropiedades, Defaults y.The following example shows how to create a Route object and set the Constraints, DataTokens, and Defaults properties.

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

public static void RegisterRoutes(RouteCollection routes)
{
    Route reportRoute = new Route("{locale}/{year}", new ReportRouteHandler());
    reportRoute.Defaults = new RouteValueDictionary { { "locale", "en-US" }, { "year", DateTime.Now.Year.ToString() } };
    reportRoute.Constraints = new RouteValueDictionary { { "locale", "[a-z]{2}-[a-z]{2}" }, { "year", @"\d{4}" } };
    reportRoute.DataTokens = new RouteValueDictionary { { "format", "short" } };
    routes.Add(reportRoute);
}
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 reportRoute As Route
    
    urlPattern = "{locale}/{year}"
    
    reportRoute = New Route(urlPattern, New ReportRouteHandler)
    reportRoute.Defaults = New RouteValueDictionary(New With {.locale = "en-US", .year = DateTime.Now.Year.ToString()})
    reportRoute.Constraints = New RouteValueDictionary(New With {.locale = "[a-z]{2}-[a-z]{2}", .year = "\d{4}"})
    reportRoute.DataTokens = New RouteValueDictionary(New With {.format = "short"})

    routes.Add(reportRoute)
End Sub

Comentarios

Utilice la DataTokens propiedad para recuperar o asignar valores asociados a la ruta que no se usan para determinar si una ruta coincide con un patrón de dirección URL.You use the DataTokens property to retrieve or assign values associated with the route that are not used to determine whether a route matches a URL pattern. Estos valores se pasan al controlador de ruta, donde se pueden usar para procesar la solicitud.These values are passed to the route handler, where they can be used for processing the request.

Se aplica a

Consulte también: