Bagikan melalui


Route.DataTokens Properti

Definisi

Mendapatkan atau mengatur nilai kustom yang diteruskan ke handler rute, tetapi yang tidak digunakan untuk menentukan apakah rute cocok dengan pola URL.

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

Nilai Properti

Objek yang berisi nilai kustom.

Contoh

Contoh berikut menunjukkan cara membuat Route objek dan mengatur Constraintsproperti , DataTokens, dan Defaults .

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

Keterangan

Anda menggunakan DataTokens properti untuk mengambil atau menetapkan nilai yang terkait dengan rute yang tidak digunakan untuk menentukan apakah rute cocok dengan pola URL. Nilai-nilai ini diteruskan ke handler rute, tempat nilai tersebut dapat digunakan untuk memproses permintaan.

Berlaku untuk

Lihat juga