How to get browser name,version,type, operating system in asp.net C#,VB.Net

Introduction: In previous articles i explained How to Count and display remaining characters in the multiline textbox in asp.net  and How to show Validation guidelines in web forms using JavaScript in Asp.net and  How to implement JavaScript validation in asp.net website and Example to implement Jquery form validations and Validate CheckBoxList using JavaScript and Call java script function from code behind file and How to get current page URL/Address in asp.net and How to Validate and upload image files in asp.net
In this article I will explain with example How to get/read/retrieve/fetch browser information like Browser Name, Browser Version, Browser Type, Platform/Operating System and also checking its support for JavaScript, Cookie, ActiveX controls etc and more using asp.net

Get browser name,version,type in asp.net
Description:  I have tested the code on 3 most popular browsers i.e. Google chrome, Mozilla Firefox and Internet Explorer and got the Browser's information as shown in figure above.
You  will get the results similar to shown in image above but not exactly same because it depends on your browser and operating system you are using .

Implementation: Let’s create an Asp.net web application to check the browser information

C#.Net Code to get browser information
  • In the code behind file(.aspx.cs) write the following code on page load event as:

protected void Page_Load(object sender, EventArgs e)
    {
        HttpBrowserCapabilities objBrwInfo = Request.Browser;
        Response.Write("Browser Name  : " + objBrwInfo.Browser);
        Response.Write("<br>");
        Response.Write("Browser Version  : " + objBrwInfo.Version);     
        Response.Write("<br>");
        Response.Write("Browser Type  : " + objBrwInfo.Type);
        Response.Write("<br>");
        Response.Write("Major version  : " + objBrwInfo.MajorVersion);
        Response.Write("<br>");
        Response.Write("Minor Version  : " + objBrwInfo.MinorVersion);
        Response.Write("<br>");
        Response.Write("Platform/Operating System  : " + objBrwInfo.Platform);
        Response.Write("<br>");
        Response.Write("Is Beta Version  : " + objBrwInfo.Beta);
        Response.Write("<br>");
        Response.Write("Java Script Version  : " + objBrwInfo["JavaScriptVersion"]);
        Response.Write("</br>");
        Response.Write("Supports javascript? : " + objBrwInfo.EcmaScriptVersion);
        Response.Write("</br>");  
        Response.Write("Does browser support cookies? : "  + objBrwInfo.Cookies);
        Response.Write("</br>");
        Response.Write("Search engine web crawler? : "  + objBrwInfo.Crawler);
        Response.Write("</br>");
        Response.Write("Is this a mobile browser? : "  + objBrwInfo.IsMobileDevice);
        Response.Write("</br>");
        Response.Write("ActiveX controls enabled? : " +  objBrwInfo.ActiveXControls);
    }


VB.Net Code to get browser information
  • In the code behind file (.aspx.vb) write the following code on page load event as:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim objBrwInfo As HttpBrowserCapabilities = Request.Browser
        Response.Write("Browser Name   : " + objBrwInfo.Browser)
        Response.Write("<br>")
        Response.Write("Browser Version  : " + objBrwInfo.Version)
        Response.Write("<br>")
        Response.Write("Browser Type  : " + objBrwInfo.Type)
        Response.Write("<br>")
        Response.Write("Major version  : " + objBrwInfo.MajorVersion.ToString())
        Response.Write("<br>")
        Response.Write("Minor Version  : " + objBrwInfo.MinorVersion.ToString())
        Response.Write("<br>")
        Response.Write("Platform/Operating System  : " + objBrwInfo.Platform)
        Response.Write("<br>")
        Response.Write("Is Beta Version  : " + objBrwInfo.Beta.ToString())
        Response.Write("<br>")
        Response.Write("Java Script Version  : " + objBrwInfo("JavaScriptVersion"))
        Response.Write("</br>")
        Response.Write("Supports javascript? : " + objBrwInfo.EcmaScriptVersion.ToString())
        Response.Write("</br>")
        Response.Write("Does browser support cookies? : " & objBrwInfo.Cookies.ToString())
        Response.Write("</br>")
        Response.Write("Search engine web crawler? : " & objBrwInfo.Crawler.ToString())
        Response.Write("</br>")
        Response.Write("Is this a mobile browser? : " & objBrwInfo.IsMobileDevice.ToString())
        Response.Write("</br>")
        Response.Write("ActiveX controls enabled? : " & objBrwInfo.ActiveXControls.ToString())
    End Sub


Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

6 comments

Click here for comments
Unknown
admin
October 04, 2013 ×

Very Helpful :)

Reply
avatar
October 04, 2013 ×

Thanks Luftai..stay connected and keep reading..):

Reply
avatar
October 05, 2013 ×

In Google Chrome returns...

Browser Name : AppleMAC-Safari
Browser Version : 5.0
Browser Type : Desktop
Major version : 5
Minor Version : 0
Platform/Operating System : WinNT
Is Beta Version : False
Java Script Version :
Supports javascript? : 1.4
Does browser support cookies? : True
Search engine web crawler? : False
Is this a mobile browser? : False
ActiveX controls enabled? : False

What is the problem ???

Reply
avatar
October 05, 2013 ×

Hello Nilesh..are you using MAC OS? on other browsers are you getting correct results?

Reply
avatar
October 07, 2013 ×

I/m using Windows 7.... And on another browser I getting correct result.....

Reply
avatar
Yuvraj
admin
November 22, 2017 ×

Nice work

Reply
avatar

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..