Wednesday, February 2, 2011

Detect Browser Types, Browser Url and Browser Capabilities in ASP.NET

Query Browser property, which contains an object HttpBrowserCapabilities. This object gets information
from the browser or client device during an HTTP request, telling her request the type and level of support
offered by the
browser or client device. The object in turn, provides information on the browser capabilities
using strongly typed properties and a generic name-value dictionary.
 
private void btnCheckBrowser_Click (object sender, System.EventArgs e)
{
   
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 string =" + 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"
       
+ "Compatible with the version of JavaScript =" +
           
browser ['JavaScriptVersion "] +" \ n ";

   
txtInfo.Text = s;
 
//Get the Brower Address Bar Url
 
Response.Write("<script>alert('"+Request.Url.ToString()+"')</script>");

}
 
NoteNote

The properties exposed by the HttpBrowserCapabilities object indicate inherent capabilities of the browser,
but do not necessarily reflect current browser settings. For example, the Cookies property indicates whether
a browser inherently supports cookies, but it does not indicate whether the browser that made the request has
cookies enabled.

 

No comments :

Post a Comment