Even though we are at version 3.5 of the .NET Framework and ASP.NET, I am still having fun exploring some of the cool features that were added in version 2.0.

For instance, ASP.NET 2.0 allows you to address browser support through browser configuration files. This set of files defines the capabilities for specific browsers. In addition, you can include browser files within a project to override settings for specific browsers.

Default browser files

An ASP.NET installation includes a set of browser files. The files use the .browser file extension and use XML to define the various browser characteristics. The files are named according to the browser they define; for instance, nokia.browser accommodates the browser used by Nokia devices. The browser files are located in the following directory:

<root Windows folder>Microsoft.NETFramework<version>CONFIGBrowsers

For example, the files are located in the following directory on a Windows XP machine using .NET Framework 2.0:

WinntMicrosoft.NETFrameworkv2.0.50727CONFIGBrowsers

This directory includes a number of browser files that define the capabilities for specific browsers. The following listing includes a portion of the browser file for Internet Explorer (ie.browser):

<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|Go.Web|Windows CE|EudoraWeb" />
</identification>
<capture></capture>
<capabilities>
<capability name="browser" value="IE" />
<capability name="extra" value="" />
<capability name="isColor" value="true" />
<capability name="letters" value="" />
<capability name="majorversion" value="" />
<capability name="minorversion" value="" />
<capability name="screenBitDepth" value="8" />
<capability name="type" value="IE" />
<capability name="version" value="" />
</capabilities>
</browser>
<browser id="IE5to9" parentID="IE">
<identification>
<capability name="majorversion" match="^[5-9]" />
</identification>
<capture></capture>
<capabilities>
<capability name="activexcontrols" value="true" />
<capability name="backgroundsounds" value="true" />
<capability name="cookies" value="true" />
<capability name="css1" value="true" />
<capability name="css2" value="true" />
<capability name="ecmascriptversion" value="1.2" />
<capability name="frames" value="true" />
<capability name="javaapplets" value="true" />
<capability name="javascript" value="true" />
<capability name="jscriptversion" value="5.0" />
<capability name="msdomversion" value="" />
<capability name="supportsCallback" value="true" />
<capability name="supportsFileUpload" value="true" />
<capability name="supportsMultilineTextBoxDisplay" value="true" />
<capability name="supportsMaintainScrollPositionOnPostback" value="true" />
<capability name="supportsVCard" value="true" />
<capability name="supportsXmlHttp" value="true" />
<capability name="tables" value="true" />
<capability name="tagwriter" value="System.Web.UI.HtmlTextWriter" />
<capability name="vbscript" value="true" />
<capability name="w3cdomversion" value="1.0" />
<capability name="xml" value="true" />
</capabilities>
</browser>

This excerpt from the browser file for Internet Explorer demonstrates the following points:

|> The root node is the browser's element. It contains one or more browser elements that define the capabilities of browsers included within its realm (like different browser versions).
|> An ID is assigned to this browser definition (IE).
|> The parent browser for this definition is mozilla (parentID attribute), which is defined in the mozilla.browser file.
|> The userAgent element specifies the HTTP user agent string, which identifies this browser. Notice that a regular expression is used to define it.
|> The capabilities element contains children defined as capability elements. These specify various capabilities of the browser. This includes such things as whether it supports tables, call-backs, frames, and so forth.
|> Capabilities for different browser versions are included in other browser elements. The definition for versions five to nine (IE5to9) is included in this listing.

In addition to defining the capabilities of a browser, there is also support for defining control adapters and their behaviour within the browser. (I outlined this in my column about CSS Friendly Control Adapters.) Once a browser is laid out, ASP.NET includes a tool for registering it with the environment.

Registering a browser

A key issue of the browser files is that ASP.NET does not have to load or read configuration files every time it requires browser information; ASP.NET provides a command line tool for registering browser set-up. After you add a new browser to the set-up, you run the AspNet_RegBrowsers tool.

This command line tool creates the required changes that allow the server to access the new browser information. Furthermore, applications do not require shut-down or restart of the Web server to recognise a new browser registration (ie, browser information is not cached as part of the application). The AspNet_RegBrowsers tool is located in the .NET installation directory:

winntMicrosoft.NETFramework<version>AspNet.RegBrowsers.exe

Choose the coverage

You may also use browser files within the realm of a Web application. This means that you can add specific browser support or behaviour to an application so it handles requests from a particular browser in a certain way.

When using Visual Studio, you can easily add a browser file to an application by selecting Add New Item (select Browser File) in a Visual Studio project. Note that browser files must live in a special folder within the ASP.NET application called App_Browsers.

First, create the folder within the application and then you can add browser files to it. A new browser file has the following default format:

<browsers>
<browser id="NewBrowser" parentID="Mozilla">
<identification>
<userAgent match="Unique User Agent Regular Expression" />
</identification>
<capture>
<userAgent match="NewBrowser (?\'version\'d+.d+)" />
</capture>
<capabilities>
<capability name="browser" value="My New Browser" />
<capability name="version" value="" />
</capabilities>
</browser>
<browser refID="Mozilla">
<capabilities>
<capability name="xml" value="true" />
</capabilities>
</browser>
</browsers>

I can format the file to support a fictitious browser called TechRepublic. The browser gets its functionality from the Mozilla line of browsers, so I use it for the parentID attribute. A unique id is assigned to it (TR). The userAgent element accepts TechRepublic.com along with major and minor version numbers. I did add one element to the capabilities to state that the browser does not support ActiveX controls.

<browsers>
<browser id="TR" parentID="Mozilla">
<identification>
<userAgent match="TechRepublic.com);.(?\'version\'(?\'major\'d+)(?\'minor\'.d+))w*" />
</identification>
<capabilities>
<capability name="browser" value="TR" />
<capability name="activeXControls" value="false" />
</capabilities>
</browser>
</browsers>

Browser support for Web applications

Have you encountered browser issues with your Web applications? Do you use ASP.NET browser files? Share your experience with the .NET community by posting to the article discussion.

Cast your .NET This was published in Cast your .NET, check every Thursday for more stories

Related links

Comments

1

RT - 01/07/08

Great article! I still use this .browser files for some basic work but mainly rely on BrowserHawk for this type of thing. If you haven't checked it out I highly recommend it: www.cyscape.com .

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

1

RT - 07/01/08

Great article! I still use this .browser files for some basic work but mainly rely on BrowserHawk for this type of ... more

Log in


Sign up | Forgot your password?

  • Staff Share a keyboard and mouse with Synergy

    Even in the era of virtualization, many IT pros (including myself) have a small army of computers sitting on, under, and around their desks. Read more »

    -- posted by Staff

  • Staff Android devs less than gruntled

    Yet more discouraging news on the Android front. Having hacked off its developer community by releasing updated SDKs to just a small group of chosen devs, Google has now given the brush-off to a petition that called for more to be given to the wider community. Read more »

    -- posted by Staff

  • Staff VMware shows how not to do it

    As a developer there will be a time when you ship a bug -- be it a stub that you left in, or a flaming, crashtastic segfault. The next time this happens and your bosses come baying for blood, point them in the direction of VMware, who this week gave the developer world a great example of how to ship a showstopper bug. Read more »

    -- posted by Staff

What's on?

  • Club Builder: Captain Obvious vs the Crackpots

    In the case of the bleeding obvious, IBM says open source needs good designers; a claim is made that China can activate your phone to snoop on you; and we take a look at the Defcon conference.