Compartilhar via


<filter> Element

Allows multiple rules to be applied in sequence.

<configuration>
   <system.web>
      <browserCaps>
         <filter>

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

Optional Attributes

Attribute Description
match A .NET Framework regular expression tested against the with attribute. If omitted, the match is assumed successful.
with A .NET Framework regular expression or string to be searched. If omitted, the string specified by the <use> element is used.

Subtag

Subtag Description
<case> Allows pattern matching to stop after processing the first successful match out of a number of alternatives.

Example

The following example demonstrates parsing the User-Agent HTTP header for any version of Internet Explorer (as long as the format of the User-Agent string remains approximately unchanged).

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

The file specifies name/value pairs in the form of assignment statements, 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>

Requirements

Contained Within: <system.web>

Web Platform: IIS 5.0, IIS 5.1, IIS 6.0

Configuration File: Machine.config, Web.config

Configuration Section Handler: System.Web.Configuration.HttpCapabilitiesSectionHandler

See Also

<browserCaps> Element | ASP.NET Configuration | ASP.NET Settings Schema