We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
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 on the exam you're probably going to see some questions about Browser Capability Functionalities so in this video I want to step you through it, I'm going to show you a little code, but understand you probably need to do a little extra outside reading, maybe even toy with some code yourself to make sure you're comfortable with this. First of all, everybody knows that Browser Capabilities are almost impossible to keep updating. We're constantly coming out with new browsers, you're constantly seeing more features in browsers, browsers handle things differently, think about it, if you're a Firefox user, how often is it that you open Firefox and the little box pops up, that there is an update available and it's promising faster, better, easier, more secure all that stuff. Alright. So how do we make sure that we keep up with all these capabilities? Well there are two main options that you have at your disposal in ASP.NET 4 and these are being introduced by the way in ASP.NET 4 and these are two options give you choices for how to deal with understanding Browser Capabilities for the browser that has made a request for a resource from your website. Now since these are being introduced in ASP.NET 4 that is pretty good indication that you could see something about these on the exam in some form. Again, it's probably going to be part of a large scenario type question where you need to understand some of your options with Browser Capabilities to be able to tell which question is viable solution to a problem or not. So the two options you have, you can either extend the current Browser Capabilities Functionality or you can totally replace the Browser Capabilities Functionality. Now let's look first at extending the current Browser Capabilities Functionality. Now when you do this, keep in mind, we're going to get more information about a browser but we don't have to open any XML browser definition files, we don't have to try to figure out that complex XML. We are simply going to create a class. We're going to create a custom class that derives from the HTTPCapabilitiesEvaluator class. Another way to say that, our class that we create will inherit from HTTPCapabilitiesEvaluator class and then inside that class that we create, we are going to override the GetBrowserCapabilities Method that's in the HTTPCapabilitiesEvaluator class. Alright. So we're going to inherit from a class and we're going to override one of the methods in that class. Now this is what that code would look like, this is a sample, this was right off Microsoft's website. Notice we're going to create a class called CustomProvider, the colon in C# tells us that we're inheriting from HTTPCapabilitiesEvaluator and so then we are going to override HTTPBrowserCapabilities GetBrowserCapabilities Method and then we're going to pass that a request that is a type of HTTPRequest. Now notice we are then going to create a variable called browserCaps and this variable is of the type HTTPBrowserCapabilities and we're going to set it equal to whatever is found, we're going to call GetHTTPBrowserCapabilities, we're going to pass in the request that came in, this HTTPRequest that is going to be header information for the browser that just made a request to our site and then notice once inside that object in the browserCaps object, we're going to check the Browser Property. If this thing says unknown, what that means is, for whatever reason we can't tell, exactly what browser this is, that has made a request if that happens. We are simply going to set the browserCaps object equal to and we are going to pass this same request now to the myBrowserCapabilitiesEvaluator. And so now this is going to go out there, look at that request, grab all the properties, load it into browserCaps and then return browserCaps to us. So we would have called this from a place where we're trying to determine exactly what we're working with. Okay. And so that extends it. We will use whatever Browser Capabilities we can see and if we can read that then we will just return this and it'll kick us out to one of our normal browser files or Blackberry or iPhone browser, whatever our files are out there for identifying the browser. If we can't see it, then we're going to go populate a new one for our self and then we can use that one. Now notice the two main key points here, is first of all, we're checking the request that came in to see if we can see the type browser, if we can't then we're going to populate our own browser object with capabilities and then work it from there. Now the browser capabilities can be added or modified using that returned browserCaps object. The only thing you have to realize and work with here is the new class that you create must be registered with the ASP.NET application and to do that, you're going to add the class name that you just created to the browserCaps Tag and you're going to use the Provider Attribute and that's out there in your Web.Config file and you can also do this in code if you would like and you're going to write that code in the Application Start Event of the Global asax file. I'm not going to show you all that here, I just want you to know that's what's got to happen, that will probably get you passed most of the information on the exam but I would strongly encourage you to go out there and read a little bit and maybe even write up an example. Okay. We can also replace the ASP.NET Browser Capabilities Functionality by creating a class that derives from HTTPCapabilitiesProvider and then we will call the GetBrowserCapabilities method when needed. Again, go out and take a look at some of this in MSDN to see exactly what to do and again, if you do this you're going to have to register this whole class, similar to what I talked about in Extending Browser Capabilities. Bottom line here, you can either extend Browser Capabilities or totally override it and do your own. You need to decide which way you want to go here, just make sure you understand what's going on here with the Browser Capabilities before you go sit 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 |