.NET Framework 3.5 SP1 內建路由引擎,將 URL 與實體 .aspx 頁面解耦,支援友善 URL。雖然舊版也能透過 URL Rewriting 達成,但路由提供更簡單、可測試的機制。
傳統 URL:/WebForms/RecipeDisplay.aspx?id=5
路由 URL:/recipe/5 或 /recipe/tacos
路由將 URL 分解為參數,導向對應處理元件。recipe 為參數一,5 或 tacos 為參數二,不再暴露實體路徑與查詢字串。
RouteUrl、RouteLink 可由參數產生正確 URL。
Global.asax 的 Application_Start 註冊路由:RouteTable.Routes.Add(new Route("recipe/{name}", new PageRouteHandler("~/RecipeDisplay.aspx")));RouteData.Values["name"] 取得參數。路由讓 Web Forms 也能擁有乾淨、SEO 友善的 URL,並解決傳統 URL Rewriting 的諸多痛點。