Powered by Blogger.

Saturday, February 22, 2014

Retrieve browser details using C#.Net




In this article we will discuss how to get browser details like browser name, browser version etc using C#.Net. You can also check my previous posts on:

- Bind dropdownlist from enum in Asp.Net

- Get nth highest lowest salary in SQL Server 2008

- Post form data to 3rd party URL in Asp.Net

C#.Net provides HttpBrowserCapabilities class to interact with browser properties. This class present in System.Web namespace. So before using the HttpBrowserCapabilities we need to import the namespace.

Full code:
lblBrowserDetails.Text = "Browser name: " + Request.Browser.Browser
            + " Browser Type: " + Request.Browser.Type
            + " Browser Version :" + Request.Browser.Version
            + " Browser Major Version: " + Request.Browser.MajorVersion
            + " Browser Minor Version: " + Request.Browser.MinorVersion
            + " Is Browser in Beta version? " + Request.Browser.Beta;

The output will be like below:

IE:
Browser name: IE Browser Type: IE8 Browser Version :8.0 Browser Major Version: 8 Browser Minor Version: 0 Is Browser in Beta version? False

Firefox:
Browser name: Firefox Browser Type: Firefox15 Browser Version :15.0 Browser Major Version: 15 Browser Minor Version: 0 Is Browser in Beta version? False

Chrome:
Browser name: Chrome Browser Type: Chrome21 Browser Version :21.0 Browser Major Version: 21 Browser Minor Version: 0 Is Browser in Beta version? False



0 comments

Post a Comment