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:

1

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.

2

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

3

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

4

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

5

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:

6

This concludes Detect Browser Capabilities in ASP.NET Web Forms

Looking for quality Windows Hosting? Look no further than Arvixe Web Hosting!

Happy Hosting

Tags: , , , , , , , , , , , , | Posted under ASP .NET 4.0, WebsitePanel Tutorials | RSS 2.0

Author Spotlight

Rodolfo Hernandez

I like photography and reading books. Currently working for Arvixe as Elgg Community Liaison. Elgg Security Expert Web Security Expert CEO of UDP SW Social Web

Leave a Reply

Your email address will not be published. Required fields are marked *