filter Element for browserCaps (ASP.NET Settings Schema)

This element specifies a list of search strings that let you apply individual settings to specific browser definitions.

Note

Using the browserCaps element in the Web.config file to define browsers is deprecated in the .NET Framework version 2.0; however, it is still supported. The data in this element is merged with the information from the browser definition files (.browser) that are located in the machine-level %SystemRoot%\Microsoft.NET\Framework\version\CONFIG\Browsers folder and any existing application-level App_Browsers folders. For more information, see Browser Definition File Schema (browsers Element).

configuration Element (General Settings Schema)
  system.web Element (ASP.NET Settings Schema)
    browserCaps Element (ASP.NET Settings Schema)
      filter Element for browserCaps (ASP.NET Settings Schema)

<filter> 
   [assignments, filter elements and case elements]
<filter>
<filter 
   match="[regular expression]" 
   with="[regular expression]" >
   [browser capability assignments, filter elements, case elements]
</filter>
<filter>
   <case>...</case>
</filter>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute

Description

match

Optional String attribute.

Specifies a .NET Framework regular expression that is tested against the with attribute. If omitted, the match is assumed successful.

with

Optional String attribute.

Specifies a .NET Framework regular expression or string to search. If omitted, the string that is specified by the use element is used.

Child Elements

Element

Description

case

Allows pattern matching to stop after processing the first successful match out of a number of alternatives.

Parent Elements

Element

Description

configuration

Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.

system.web

Specifies the root element for the ASP.NET configuration settings in a configuration file and contains configuration elements that configure ASP.NET Web applications and control how the applications behave.

browserCaps

Specifies the settings of supported browsers and the capabilities for the browsers. The browserCaps element can be updated as required to specify new browsers and capabilities.

For a list of valid browser properties, see HttpBrowserCapabilities.

Remarks

The browserCaps element specifies a list of search strings that let you apply individual settings to specific browser definitions. The rules that are contained in the list are applied in sequence. The first child case element that matches is evaluated and the remaining child case elements are ignored.

Default Configuration

In the .NET Framework version 2.0, the filter element is not configured because the browserCaps element is deprecated in favor of using browser definition files to specify supported browsers and the capabilities for the browsers. For more information, see Browser Definition File Schema (browsers Element).

In the .NET Framework versions 1.0 and 1.1, the default filter elements that are configured in the Machine.config file are too numerous to list here. For updates to the browser data go to http://www.cyscape.com/browsercaps. Periodic device updates replace this browser capabilities section.

Example

The following code example demonstrates how to parse the User-Agent HTTP header for any version of Microsoft Internet Explorer, as long as the format of the User-Agent string remains approximately unchanged.

The example makes use of the .NET Framework Regular Expressions and the ability of regular expressions to capture subexpressions in order to move version numbers directly from the User-Agent string to the browserCaps element.

The file specifies name/value pairs in the form of assignment statements, which are similar to Microsoft Internet Information Services (IIS) browscap.ini files. For example, the line "browser=IE" sets the value of the browser field to the string "IE".

<configuration>
   <browserCaps>
      <result type="System.Web.HttpBrowserCapabilities, System.Web"/>
      <use var="HTTP_USER_AGENT"/>
      browser=Unknown
      version=0.0
      majorversion=0
      minorversion=0
      frames=false
      tables=false
      cookies=false
      backgroundsounds=false
      <filter>
         <case match="^Mozilla[^(]*\(compatible; MSIE 
            (?'ver'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))
            (?'extra'.*)">
            browser=IE
            version=${ver}
            majorver=${major}
            minorver=${minor}
            <case match="^2\." with="%{version}">
               tables=true
               cookies=true
               backgroundsounds=true
               <case match="2\.5b" with="%{version}">
                  beta=true
               </case>
            </case>
         </case>
      </filter>
   </browsercaps>
</configuration>

Element Information

Configuration section handler

HttpCapabilitiesSectionHandler

Configuration member

Browsers

Configurable locations

Machine.config

Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config

Requirements

Microsoft Internet Information Services (IIS) version 5.0, 5.1, or 6.0

The .NET Framework version 2.0 (deprecated), 1.0, or 1.1

Microsoft Visual Studio 2003 or Visual Studio 2005

See Also

Tasks

How to: Detect Browser Types and Browser Capabilities in ASP.NET Web Pages

How to: Configure Specific Directories Using Location Settings

How to: Lock ASP.NET Configuration Settings

Reference

browserCaps Element (ASP.NET Settings Schema)

case Element for filter for browserCaps (ASP.NET Settings Schema)

system.web Element (ASP.NET Settings Schema)

configuration Element (General Settings Schema)

result Element for browserCaps (ASP.NET Settings Schema)

use Element for browserCaps (ASP.NET Settings Schema)

Browser Definition File Schema (browsers Element)

System.Configuration

System.Web.Configuration

HttpCapabilitiesSectionHandler

Browsers

Concepts

ASP.NET Web Server Controls and Browser Capabilities

ASP.NET Configuration File Hierarchy and Inheritance

Securing ASP.NET Configuration

ASP.NET Configuration Scenarios

Other Resources

General Configuration Settings (ASP.NET)

ASP.NET Configuration Settings

ASP.NET Web Site Administration

ASP.NET Configuration API