Поделиться через


<browserCaps> Element

Controls the settings of the browser capabilities component. The <browserCaps> element can be declared at the machine, site, application, and subdirectory level. The <browserCaps> element can be updated as required to detect future browsers and browser capabilities.

For a list of valid browser properties, see the HttpBrowserCapabilities class.

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

<browserCaps>
   <result type="class"/>
   <use var="HTTP_USER_AGENT"/>
        browser=Unknown
        version=0.0
        majorver=0
        minorver=0
        frames=false
        tables=false
      <filter>
         <case match="Windows 98|Win98">
            platform=Win98
         </case>
      <case match="Windows NT|WinNT">
         platform=WinNT
      </case>
   </filter>
   <filter match="Unknown" with="%(browser)">
      <filter match="Win95" with="%(platform)">
      </filter>
   </filter>
</browserCaps>

Subtags

Subtag Description
<use> Specifies the server variables used while evaluating <filter>, <case>, and assignments in the section.
<filter> Evaluates the first child <case> element that matches; the rest are ignored.
<result> Specifies the HttpCapabilitiesBase-derived class used to hold the resulting key/value string pairs from parsing this section (for example, browser, version, and majorver in the syntax block above). This string is used at run time to create the return type.

Remarks

Lines of the form capsVariableName=regular expression are assignments. Use the syntax %{capsVariableName} or ${captureGroupName} in match attributes and on the right-hand side of assignments. For more information on using regular expressions, see .NET Framework Regular Expressions. For the full <browserCaps> section, with a more complete example of this syntax, see the Machine.config file that is installed with the .NET Framework.

The name/value pairs that are captured with capsVariableName are accessible through the Item property of the HttpBrowserCapabilities that is inherited from HttpCapabilitiesBase. The Item property is the default indexer property in C#.

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

ASP.NET Configuration | ASP.NET Settings Schema