<case> Element

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

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

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

Required 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.

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>

Remarks

All <filter> and <case> elements can contain assignments and other <filter> and <case> elements. The difference between <case> and <filter> groups is this: after a <filter> group is evaluated, execution continues with the statement after the group, but after a <case> group is successfully matched and evaluated, execution skips to the end of the enclosing group.

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 | <filter> Element | ASP.NET Configuration | ASP.NET Settings Schema