A Web application can access the current instance of the HttpBrowserCapabilities object using the HttpRequest.Browser property. This object is read-only, and contains properties for each capability. The HttpBrowserCapabilities object is cached and might be used again for a different request from the same type of browser.
Predefined browser definition files are stored in the %SystemRoot%\Microsoft.NET\Framework\version\CONFIG\Browsers directory. Application-level browser-definition files can be placed in the application's App_Browsers directory. In both locations, browser definition files must have a .browser file name extension.
How it works?
At run-time, browser-definition file information is merged into a collection of known browsers in a BrowserCapabilitiesFactory object. When a request is made, ASP.NET identifies the requesting browser by the request header, and compiles an HttpBrowserCapabilities object that corresponds to the type of the requested browser. This is done by starting with an empty dictionary, and applying the following recursive steps against the browser definition tree:
- Start at the default browser definition, which is always considered a successful match.
- Merge capability values specified in this browser definition into the capabilities dictionary for this browser. Values specified in a browser definition override values set in a parent.
- Evaluate each child definition to determine a match. For each matching child, start at step 1 again. Browser definitions are evaluated after gateway definitions. If the user agent matches more than one browser definition or more than one gateway definition, an exception is thrown at run-time.
Syntax for Browser Definition File:
<browsers>
<browser id="browser name" parentID="parent browser name" refID="reference ID">
<identification>
<userAgent match="regular expression"
nonMatch="regular expression" />
<header match="regular expression" name="header name" nonMatch="regular expression" />
<capability match="regular expression" name="capability name" nonMatch="regular expression" />
</identification>
<capture>
<userAgent match="regular expression" />
<header match="regular expression" name="header name" />
<capability match="regular expression" name="capability name" />
</capture>
<capabilities>
<capability name="capability name" value="capability value" />
</capabilities>
<controlAdapters markupTextWriterType="type name">
<adapter adapterType="name of adapter class" controlType="name of control class" />
</controlAdapters>
<sampleHeaders>
<header name="header name" value="header value" />
</sampleHeaders>
</browser>
<gateway id="gateway ID" parentID="parent browser ID">
<!-- Same child elements as for <browser>.
<identification></identification>
<capture></capture>
<capabilities></capabilities>
<controlAdapters></controlAdapters>
<sampleHeaders></sampleHeaders>
-->
</gateway>
<defaultBrowser id="Default" parentID="parent browser ID"
refID="reference ID" >
<!-- Same child elements as for <browser>.
<identification></identification>
<capture></capture>
<capabilities></capabilities>
<controlAdapters></controlAdapters>
<sampleHeaders></sampleHeaders>
-->
</defaultBrowser>
</browsers>
Sample C# code to read browser details in ASP.Net:
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
For more information refer below link:
http://msdn.microsoft.com/en-us/library/vstudio/ms228122(v=vs.100).aspx
No comments:
Post a Comment