Detect Browser Capabilities in ASP.NET Web Forms

In the development of ASP.net applications, it is very important to know if this will be compatible with various browsers. Knowing the capabilities of browsers, we may know if our application will run correctly. In this article, I’ll show you how to check the capabilities of a browser from an asp.net web form.

HttpBrowserCapabilities object

This object gets information from the browser or client device during an HTTP request, telling your application the type and level of support the browser or client device offers.

Then I’ll show you a small example of a script to detect browser capabilities. Follow these steps to create a simple ASP.NET application using Visual C#:

Click in the top menu File -> New Project:

In the New Project dialog box, select Templates -> Visual C# and click ASP.NET Web Application. In the Name text box, type a name for the application.

In the next step under ASP.NET Templates 4.5.2, click Web Forms:

The design of the form, only consists of a button to process, and a label to display the information:

Inside the button, paste the following code, which will serve to determine browser capabilities:

Code:

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”;

Label1.Text = s;

We used the HttpBrowserCapabilities object to obtain browser information.

And that’s it! As a result we have the following information to run our application: