DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 To show browser capabilities using ASP.NET 2.0 and C#

This tutorial will show you how to gather your web browser capabilities using ASP.NET 2.0 and C#.

The class of HttpBrowserCapabilities will enable the server to gather information on the capabilities of the browser that is running on the client. Namespace of this class: System.Web.

First, import the namespace of System.Web:

using System.Web;

In order to use the class of HttpBrowserCapabilities, we need initialize an instance of Request.Browser object. Then we can use this class to list IE properties.

HttpBrowserCapabilities bc = Request.Browser;
Label1.Text = "Welcome! You are using" + bc.Browser + "v." + bc.Version + "on a" + bc.Platform + "machine";

ActiveControls.Text = bc.ActiveXControls.ToString();
AOL.Text = bc.AOL.ToString();
Beta.Text = bc.Beta.ToString();
BackgroundSounds.Text = bc.BackgroundSounds.ToString();
Browser.Text = bc.Browser.ToString();
CDF.Text = bc.CDF.ToString();
Cookies.Text = bc.Cookies.ToString();
Crawler.Text = bc.Crawler.ToString();
Frames.Text = bc.Frames.ToString();
JavaApplets.Text = bc.JavaApplets.ToString();
EcmaScriptVersion.Text = bc.EcmaScriptVersion.ToString();
win16.Text = bc.Win16.ToString();
Version.Text = bc.Version.ToString();
VBScript.Text = bc.VBScript.ToString();
win32.Text = bc.Win32.ToString();
Type.Text = bc.Type.ToString();
Tables.Text = bc.Tables.ToString();
Platform.Text = bc.Platform.ToString();
MajorVersion.Text = bc.MajorVersion.ToString();
MinorVersion.Text = bc.MinorVersion.ToString();
MsDomVersion.Text = bc.MSDomVersion.ToString();

The front end Default.aspx page looks something like this:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Using Performance Counters</title>
</head>

<body>
<form id="form1" runat="server">
<br />
<asp:Label ID="Label1" runat="server" Width="709px"></asp:Label>
<br />
<br />
<asp:Table ID="Table1" runat="server" Height="186px" Width="245px">
<asp:TableRow runat="server">
<asp:TableCell runat="server" Text="Propety" Width="50%" />
<asp:TableCell runat="server" Text="Value" Width="50%" />
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">ActiveControls:</asp:TableCell>
<asp:TableCell ID="ActiveControls" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">AOL:</asp:TableCell>
<asp:TableCell ID="AOL" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">BackgroundSounds:</asp:TableCell>
<asp:TableCell ID="BackgroundSounds" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Beta:</asp:TableCell>
<asp:TableCell ID="Beta" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Browser:</asp:TableCell>
<asp:TableCell ID="Browser" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">CDF:</asp:TableCell>
<asp:TableCell ID="CDF" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Cookies:</asp:TableCell>
<asp:TableCell ID="Cookies" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Crawler:</asp:TableCell>
<asp:TableCell ID="Crawler" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">EcmaScriptVersion:</asp:TableCell>
<asp:TableCell ID="EcmaScriptVersion" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Frames:</asp:TableCell>
<asp:TableCell ID="Frames" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">JavaApplets:</asp:TableCell>
<asp:TableCell ID="JavaApplets" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Win16:</asp:TableCell>
<asp:TableCell ID="win16" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Version:</asp:TableCell>
<asp:TableCell ID="Version" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">VBScript:</asp:TableCell>
<asp:TableCell ID="VBScript" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Win32:</asp:TableCell>
<asp:TableCell ID="win32" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Type:</asp:TableCell>
<asp:TableCell ID="Type" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Tables:</asp:TableCell>
<asp:TableCell ID="Tables" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">Platform:</asp:TableCell>
<asp:TableCell ID="Platform" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">MajorVersion:</asp:TableCell>
<asp:TableCell ID="MajorVersion" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">MinorVersion:</asp:TableCell>
<asp:TableCell ID="MinorVersion" runat="server"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">MsDomVersion:</asp:TableCell>
<asp:TableCell ID="MsDomVersion" runat="server"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>



Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!