Route.DataTokens 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定自訂值,這些自訂值會傳遞給路由處理常式,但不會用來判斷路由是否符合 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
屬性值
包含自訂值的物件。
範例
下列範例示範如何建立 Route 物件,並設定 Constraints、 DataTokens和 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
備註
DataTokens您可以使用 屬性來擷取或指派與路由相關聯的值,這些值不會用來判斷路由是否符合URL模式。 這些值會傳遞至路由處理常式,以用來處理要求。