1 00:00:00,560 --> 00:00:04,766 In the previous video we left the question as to how MVC. 2 00:00:04,766 --> 00:00:10,469 associated the URL comic books/detail with our controller action unanswered. 3 00:00:10,469 --> 00:00:12,787 Let's answer that question now. 4 00:00:12,787 --> 00:00:17,914 In the URL http://teamtreehouse.com/, 5 00:00:17,914 --> 00:00:25,930 http is the protocol, and teamtreehouse.com is the host name. 6 00:00:25,930 --> 00:00:30,080 Typically, the host name is the domain name of the website. 7 00:00:30,080 --> 00:00:36,154 However, when running websites locally, a special name, localhost is used. 8 00:00:36,154 --> 00:00:39,947 The number following the colon, after the host name, 9 00:00:39,947 --> 00:00:43,584 is our port number, which in my case is 50153. 10 00:00:43,584 --> 00:00:48,143 Your port number might be different as Visual Studio assigns a random 11 00:00:48,143 --> 00:00:51,840 number when creating ASP.NET projects. 12 00:00:51,840 --> 00:00:57,680 Using a different explicit port number for each project allows each to be run locally 13 00:00:57,680 --> 00:01:02,710 at the same even though they're all using the same host name local host. 14 00:01:03,890 --> 00:01:08,170 If the terms URL, Protocol, Host Name or 15 00:01:08,170 --> 00:01:11,630 Port are unfamiliar to you, check the teachers notes for 16 00:01:11,630 --> 00:01:16,190 links to resources that will explain these concepts in detail. 17 00:01:16,190 --> 00:01:22,026 The URL, http://localhost:50153/ 18 00:01:22,026 --> 00:01:27,866 would display the default page for our website. 19 00:01:27,866 --> 00:01:31,994 Often this page is referred to as the Home Page. 20 00:01:31,994 --> 00:01:39,903 For the URL, http://localhost:50153/ComicBooks/Detail, 21 00:01:39,903 --> 00:01:47,210 everything to the right of the port number is known as the Path. 22 00:01:47,210 --> 00:01:51,140 So while the combination of the host name and the port number 23 00:01:51,140 --> 00:01:56,180 is used to determine which website the request is intended for, the path is used 24 00:01:56,180 --> 00:02:01,110 to determine which resource within that website is being requested. 25 00:02:01,110 --> 00:02:05,960 Whenever MVC processes the request, it uses simple pattern matching 26 00:02:05,960 --> 00:02:09,470 against the path to determine the name of the controller and 27 00:02:09,470 --> 00:02:14,125 action that should be used in the form of controller/action. 28 00:02:14,125 --> 00:02:19,890 So the URL path, ComicBooks/Detail would map to a controller 29 00:02:19,890 --> 00:02:24,800 named ComicBooks and an action method named Detail. 30 00:02:25,810 --> 00:02:31,619 The process of matching a URL to a controller action is called url routing. 31 00:02:31,619 --> 00:02:36,270 URL routing is not unique to Asp.net MVC. 32 00:02:36,270 --> 00:02:39,380 Many other web frameworks, both server side and 33 00:02:39,380 --> 00:02:42,880 client side, use the concept of URL routing. 34 00:02:42,880 --> 00:02:46,030 Let's take a closer look at why we're getting an error 35 00:02:46,030 --> 00:02:48,790 when requesting our website's home page. 36 00:02:48,790 --> 00:02:51,780 When making a request, I'll supply in a path, 37 00:02:51,780 --> 00:02:56,960 MVC will default the controller name to home and the action name to index. 38 00:02:56,960 --> 00:03:02,106 We're getting a 404 error because our project doesn't contain a controller 39 00:03:02,106 --> 00:03:06,965 named home controller, let alone a method on that controller named index. 40 00:03:06,965 --> 00:03:12,101 If we were to request the URL path comic books, MVC would successfully find 41 00:03:12,101 --> 00:03:17,074 our comic books controller but we'd still get a 404 error because our 42 00:03:17,074 --> 00:03:21,987 controller currently doesn't contain an action method named index. 43 00:03:21,987 --> 00:03:23,052 In a later video, 44 00:03:23,052 --> 00:03:28,430 we'll add the index action method which will display a list of comic books. 45 00:03:28,430 --> 00:03:32,290 We're just scratching the surface of what URL routing is capable of. 46 00:03:32,290 --> 00:03:36,400 But for now, these basic concepts are just what we need to know 47 00:03:36,400 --> 00:03:39,300 in order to continue building out our website. 48 00:03:39,300 --> 00:03:44,700 Our controller's detail action method currently just returns a string literal. 49 00:03:44,700 --> 00:03:47,650 Let's see if we can improve upon that design in the next video.