MVC
路由定義 URL 模式和處理應用程序資訊。應用程序的所有已配置路由都存在 RouteTable 中,當請求傳入時,路由引擎將使用它來判斷合適的處理程序類別或檔案。
用來定義不要透過 Routing 處理的網址,例如: 不會處理網址 localhost/test.axd/abc/123。
(* 表示後面無論接幾個路徑,如:/xxx/xxx 或/xxx/xxx/xxx 皆不處理)
id = UrlParameter.Optional
,id 路由參數為選擇性,如果沒有為空值。
{controller}/{action}/{id}
表示定義的 URL 樣式包含三個路由參數,分別命名為 controller、action 與 id。localhost
,那預設的路由為 localhost/home/index
。/Home/About/123
,那 controller 的路由值是 Home,action 的路由值是 About,而 id 這個路由值就是 123。url: customer/who/{id}
。id = UrlParameter.Optional
,表示網址必須要有路由參數 id。http://localhost/customer/who/100
,路由比對為 Customer Controller 的 Action Who。限制路由參數 id 只能是數字。
要在 Global.asax.cs 的 Application_Start 註冊 RouteConfig.cs,將所有路由包含到 RouteTable 中。