ルーティングはGlobal.asaxで定義されている。
- public class MvcApplication : System.Web.HttpApplication
- {
- public static void RegisterRoutes(RouteCollection routes)
- {
- routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
- routes.MapRoute(
- "Default", // ルート名
- "{controller}/{action}/{id}", // パラメーター付きの URL
- new { controller = "Home", action = "Index", id = UrlParameter.Optional } // パラメーターの既定値
- );
- }
- protected void Application_Start()
- {
- AreaRegistration.RegisterAllAreas();
- RegisterRoutes(RouteTable.Routes);
- }
- }
RouteCollection型となっているので複数のルーティングを定義できるのだろう。
初期状態では”Default”というルーティングが定義されていて、
「コントローラー名/アクション名/パラメータ」でルーティングされるようだ。
ControllerにはHome、actionにはIndexが初期値として定義してあるので、例えば
「http://ホスト名/コントローラ名」でアクセスされたときにはIndexアクションが実行されてIndexページが返るという仕掛けなのだろう。
0 件のコメント:
コメントを投稿