Page.RouteData Page.RouteData Page.RouteData Page.RouteData Property


取得目前 RouteData 執行個體的 RequestContext 值。Gets the RouteData value of the current RequestContext instance.

 property System::Web::Routing::RouteData ^ RouteData { System::Web::Routing::RouteData ^ get(); };
public System.Web.Routing.RouteData RouteData { get; }
member this.RouteData : System.Web.Routing.RouteData
Public ReadOnly Property RouteData As RouteData


目前 RouteData 執行個體的 RequestContext 值。The RouteData value of the current RequestContext instance.


如果頁面正在執行以回應要求,透過 ASP.NET 路由中,這個屬性會提供存取權已傳遞為路由資料的 URL 參數值。If a page is running in response to a request made through ASP.NET routing, this property provides access to the URL parameter values that were passed as route data. 如果實體的 url,而不是路由 URL 的回應中執行網頁時,這個屬性是nullIf the page runs in response to a physical URL instead of a route URL, this property is null. 下列範例示範如何擷取名為 URL 參數的值yearThe following example shows how to extract the value of a URL parameter that is named year.

Dim year As Integer = Convert.ToInt32(Page.RouteData.Values("year"))  
int year = Convert.ToInt32(Page.RouteData.Values["year"])  

如果使用的 URL 模式來定義的路由{locale}/{year}網域,以及要求的 URL 是否會包含值 「 2010 」 執行此程式碼。If the route is defined by using the URL pattern {locale}/{year} for the domain, and if the requested URL is, year will contain the value "2010" when this code runs.

如需有關 ASP.NET 路由的詳細資訊,請參閱 < ASP.NET 路由For more information about ASP.NET routing, see ASP.NET Routing.