Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Now Routing in ASP.NET 4 promises to be a game changing technology and in this video I want to show you how we go about mapping a route to a page resource. Now what we're going to start with is we have an original URL and you will notice that it's www.VTC.com slash products question mark category equal development. This is not a user friendly URL for most people. We want our routed URL to look like this. WWW.VTC.com slash products slash development very easy for people to read and they could even just type that URL based on memory. Now routes are defined in the Global asax file, so anything to do with routes, we're going to put in a Global asax file and the good news is you can define as many routes as you need. Now let me warn you, the first time you see this or work with this, it feels very funky and you're like, no this is not going to catch on. Keep in mind, I had the opportunity, didn't realize it at the time but way back in the late 80's it could have been mid 80's, I really don't remember but sometime in the 80's, I was invited to, well myself and a bunch of fellow nerds at the company that I was working with at the time in, in IT administration were invited to the Apple Users Group down in Birmingham, Alabama. They met a shopping mall and they were going to demonstrate this great new thing in the computer world that was going to change our world, it was called the World Wide Web. So we went down there and this nerd sat up there on his Apple machine and it was all text based and he connected and shared some information with some various machines in two or three different places in the world. And we all unanimously after it was over with, decided this wasn't going anywhere, we didn't really see the purpose for it, it wasn't user friendly, wasn't going to happen. Right. So now, you understand my prowess for choosing winning technologies. Okay. So this is not my opinion that Routing's going to be big, it is already big and it's also by the way, it is really being exploited in the MVC world, the Model View Controller world, which if any of you guys have tinkered with iPhone or iPad development that is based on the Model View Controller development pattern and so all this kind of runs together. Okay. So anyway Routing is a pretty big deal here. Now let's talk about how we're going to actually route resource to an URL that's different that we're normally used to seeing. First of all, both of what I show you here need to be added to the Global asax file. Here's the first one, we're going to build a method here called RegisterRoutes. We're going to put this out there, a function and we're going to RegisterRoutes and notice we're going to pass it some routes and we're going to create a variable called Routes and it's a type of RouteCollection. And so we're going to pass information in when we call this and it is going to map a page route into this route. This is not complete code here, but this is the heart of what makes the difference. There's not enough time here in this course to go very deeply into Routing and MVC and all that so I just going to kind of touch on it. So understand this is what you're going to see, you'll get very used to this later on, trust me. So anyway, once we get into our function here and notice routes.MapPageRoute then we pass it the products software. Now this is the name of the route that we're creating then products slash category that's the URL but notice category here is a parameter and so what we're basically saying is, anything that has products slash and then a parameter or a category out here, we're going to take that and then this is the Web Forms Page to call. Okay. This is saying in the current directory or this is mapping it into the directory where we are, relative, we don't want to get into all that right now but notice the Products.aspx page is the one we're going to call. So we have mapped anything that has products slash category, we're going to map it the Products.aspx page. Now once we get that done, we also need to add RegisterRoutesRouteTable.Routes which we're actually kind of loading in here to the Application Start Event in the Global asax page. Now this is again, going to be a game changer. It's something you need to work with a little bit at a time, I would strongly encourage to go out and read about Routing, you might even want to play with it just a little bit. There's all kind of tutorials on the web, there's all kind of information out there, Microsoft's extremely proud of it. You need to know what Routing is, you need to know what it does and you need to have just a general understanding of, of how you pull this of when you go take this exam.
| Course: | Designing and Developing ASP.NET 4 Web Apps (Exam 70-519) |
| Author: | Mark Long |
| SKU: | 34292 |
| ISBN: | 978-1-61866-029-9 |
| Release Date: | 2011-12-31 |
| Duration: | 8.5 hrs / 108 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |