Monday, 1 June 2015

Check Browser Name Along-with Version C#.Net


Check Browser Name Along-with Version C#.Net


We can get the details of the Browser in which the web-application is running and using this information we can prevent running certain script or code if the browser is in-compatible..

Code-Snippet:



protected void Page_Load(object sender, EventArgs e)
        {
            System.Web.HttpBrowserCapabilities browser = Request.Browser;
            string s = "Browser Capabilities <br/>"
                + "Type = " + browser.Type + "<br/>"
                + "Name = " + browser.Browser + "<br/>"
                + "Version = " + browser.Version + "<br/>"
                + "Major Version = " + browser.MajorVersion + "<br/>"
                + "Minor Version = " + browser.MinorVersion + "<br/>"
                + "Platform = " + browser.Platform + "<br/>"
                + "Is Beta = " + browser.Beta + "<br/>"
                + "Is Crawler = " + browser.Crawler + "<br/>"
                + "Is AOL = " + browser.AOL + "<br/>"
                + "Is Win16 = " + browser.Win16 + "<br/>"
                + "Is Win32 = " + browser.Win32 + "<br/>"
                + "Supports Frames = " + browser.Frames + "<br/>"
                + "Supports Tables = " + browser.Tables + "<br/>"
                + "Supports Cookies = " + browser.Cookies + "<br/>"
                + "Supports VBScript = " + browser.VBScript + "<br/>"
                + "Supports JavaScript = " +
                    browser.EcmaScriptVersion.ToString() + "<br/>"
                + "Supports Java Applets = " + browser.JavaApplets + "<br/>"
                + "Supports ActiveX Controls = " + browser.ActiveXControls
                      + "<br/>"
                + "Supports JavaScript Version = " +
                    browser["JavaScriptVersion"]  + "<br/><br/>";
 
             
 
            Response.Write(s);
 
            switch (browser.Browser.ToUpper().Trim())
            {
                // WHY No OPERA BROWSER,because opera and chrome user agent is same, 
                // the browser.Browser will return Chrome value in Opera
                case "CHROME": Response.Write("<b>application support your browser</b>"); break;
                case "INTERNETEXPLORER": Response.Write("<b>application does not support your browser</b>"); break;
                case "FIREFOX": Response.Write("<b>application support your browser</b>"); break;
                case "SAFARI": Response.Write("<b>application support your browser</b>"); break;
                default: break;
            }
        } 

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top