2005-03-31
| Table of Contents: |
| Rate This Article: | Add This Article To: |
( Page 3 of 3 )
.BROWSER File">
Understanding the .BROWSER File
Working with Machine.CONFIG every time you want to make a browser change is difficult. You have to locate the correct section and hope that you don't make a mistake entering the new information. In addition, it's easy to overwrite the changes you make, which means you have to start all over again.
Obviously, you need a better way to add new browsers to ASP.NET, which is precisely what ASP.NET 2.0 does. A .BROWSER file defines the parameters of a particular browser using XML entries, similar to those found in the Machine.CONFIG file, but using a separate file for each browser. You add a new browser by adding a new file to the folder. You'll find the ASP.NET 2.0 .BROWSER files in the \WINDOWS\Microsoft.NET\Framework\v2.0.40607\CONFIG\Browsers folder of your system.
Unlike the Machine.CONFIG entries, those in a .BROWSER file use real XML to present information. The files also have a consistent and easier to understand appearance. Even better: you get all of this additional functionality and ease-of-use without any changes
to the code you create. Accessing client information is still as easy as using the Request.Browser object.
Listing 3 shows part of a typical .BROWSER file.
<browsers>
<browser id="IE" parentID="Mozilla">
<identification>
<userAgent match="^Mozilla[^(]*\([C|c]ompatible;\s*MSIE
(?'version'(?'major'\d+)(?'minor'\.\d+)
(?'letters'\w*))(?'extra'[^)]*)" />
<userAgent nonMatch="Opera" />
<userAgent nonMatch="Go\.Web" />
<userAgent nonMatch="Windows CE" />
<userAgent nonMatch="EudoraWeb" />
</identification>
<capture>
</capture>
<capabilities>
<capability name="browser" value="IE" />
<capability name="extra" value="${extra}" />
<capability name="isColor" value="true" />
<capability name="letters" value="${letters}" />
<capability name="majorversion" value="${major}" />
<capability name="minorversion" value="${minor}" />
<capability name="screenBitDepth" value="8" />
<capability name="type" value="IE${major}" />
<capability name="version" value="${version}" />
</capabilities>
</browser>
ASP.NET 2.0 adds another wrinkle to the whole issue of working with browsers. Instead of forcing the server to read an INI or CONFIG file every time it requires browser information, ASP.NET 2.0 provides a means to create a class factory from the information. After you add a new browser to the setup, you run the AspNet_RegBrowsers tool. This tool creates the required changes that allow the server to access the new browser information. You don't have to shut down any of your applications, because the information isn't cached as part of the application. In addition, because of the way the .NET Framework does store the information, you receive a significant performance boost.
The .BROWSER files let you specify a few new items. The most important is a control adapter. This element defines a specific behavior for controls based on the browser's capabilities. In short, these entries modify the behavior of the control globally, so you don't need to perform the change in your code. Here's an example of a control adapter for Internet Explorer.
<controlAdapters> <adapter controlType="System.Web.UI.WebControls.FileUpload" adapterType="System.Web.UI.WebControls.Adapters.HtmlFileUploadAdapter"/> </controlAdapters>
In this case, the control adapter modifies the behavior of the FileUpload control, but you can attach a behavior to any control. You won't find this entry in the Mozilla.BROWSER file because the Mozilla browser doesn't provide the required support.
A final new piece of browser functionality that appears in ASP.NET 2.0 is per-control customization based on browser. The tag you use to define the control now contains special entries that make it act differently based on the browser making the request. Here's an example of a customized browser entry.
<asp:label runat="server" text="Undefined Browser" IE:text="Any Internet Explorer Browser" IE5:text="Internet Explorer 5 Browser" PIE:text="Pocket PC Browser" />
This label can contain one of four pieces of text, depending on the browser that makes the request. When the server doesn't detect one of the specific browsers, it outputs Undefined Browser. On the other hand, when the server detects Internet Explorer 5, it outputs Internet Explorer 5 Browser instead. The idea is that you can customize output based on a particular browser's needs.
The Bottom Line
With each new version of ASP, Microsoft keeps working on the browser compatibility issue. With ASP.NET 2.0, it appears that Microsoft might finally have a winning combination of features, functionality, and ease-of use. In addition, since you can create a class factory with the content of the .BROWSER files, ASP.NET doesn't have to read these files for information continually; the configuration data is always available. In short, ASP.NET not only makes browser updates easier, but also adds a performance boost.
![]() |
|


