tailieunhanh - Visual studio 2010 part 29

Microsoft Visual Studio 2010: A của Hướng dẫn mới bắt đầu Ví dụ 9-5 cho thấy rằng sự kiện Application_Start gọi một phương thức có tên RegisterRoutes, tuyến đường đi qua các tài sản của lớp RouteTable. Các tài sản Tuyến đường là một RouteCollection tĩnh, có nghĩa là chỉ có một bản sao cho toàn bộ ứng dụng, và nó sẽ tổ chức nhiều tuyến đường. | 264 Microsoft Visual Studio 2010 A Beginner s Guide Listing 9-5 shows that the Application_Start event invokes a method named RegisterRoutes passing the Routes property of the RouteTable class. The Routes property is a static RouteCollection meaning that there is only one copy for the entire application and it will hold multiple routes. When the application starts this collection will be empty and the RegisterRoutes method will populate the collection with routes for this application. Routing works by pattern matching which you can see through the two statements in the RegisterRoutes method IgnoreRoute and MapRoute. IgnoreRoute is useful for situations where you want to let IIS request the exact URL. In this case it is any file with the .axd extension regardless of parameters. The MapRoute method shows a common pattern for matching URLs to controllers actions and parameters. The first parameter is the name of the route. The second parameter describes the pattern where each pattern match is defined between curly braces. Based on the URL http localhost 1042 Home About the pattern controller action id matches Home to controller and About to action there is no match for id . Therefore MVC will append Controller to the URL segment that matches controller meaning that the Controller name to instantiate is HomeController. About is the method inside of HomeController to invoke. Since About doesn t have parameters supplying the id is unnecessary. The third parameter for MapRoute specifies default values where the key matches the pattern parameter and the value assigned to the key is what MVC uses when it doesn t find a pattern match with the URL. Here are a couple of examples http localhost 1042 invokes the Index method of HomeController because no Controller or action matches and the defaults are Home for controller and Index for action . http localhost 1042 Home invokes the Index method of HomeController because no action was specified and the default .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.