Click here to Skip to main content
15,881,559 members
Articles / Web Development / ASP.NET
Article

Detect the browser using ASP.NET and C#

Rate me:
Please Sign up or sign in to vote.
3.16/5 (20 votes)
19 Dec 20012 min read 266.4K   3.9K   72   8
A Simple ASP.NET program for detecting browser type that clients use

Image 1

This article intends to show how to detect the browser on the clients side. I use the HttpBrowserCapabilities class using the C# language. The HttpBrowserCapabilities class gives information on the capabilities of the browser that is running on the client. It needs the  System.Web namespace. HttpBrowserCapabilities properties are accessible through the Browser property of ASP.NET's intrinsic

Request
object. Here's the HttpBrowserCapabilities members:

 Properties  Meaning
 ActiveXControls Gets a value indicating whether the client browser supports ActiveX controls.
 AOL Gets a value indicating whether the client is an America Online (AOL) browser.
 BackgroundSounds Gets a value indicating whether the client browser supports background sounds.
 Beta Gets a value indicating whether the browser is a beta release.
 Browser Gets the browser string (if any) that was transmitted in the User-Agent header.
 CDF Gets a value indicating whether the client browser supports Channel Definition Format (CDF) for webcasting.
 ClrVersion [To be supplied.]
 Cookies Gets a value indicating whether the client browser supports cookies.
 Crawler Gets a value indicating whether the client browser is a Web crawler search engine.
 EcmaScriptVersion Gets the version number of ECMA script that the client browser supports.
 Frames Gets a value indicating whether the client browser supports HTML frames.
 Item (inherited from HttpCapabilitiesBase) Allows access to individual dictionary values.

In C#, this property is the indexer for the HttpBrowserCapabilities class.

 JavaApplets Gets a value indicating whether the client browser supports Java applets.
 JavaScript Gets a value indicating whether the client browser supports JavaScript.
 MajorVersion Gets the major (that is, integer) version number of the client browser.
 MinorVersion Gets the minor (that is, decimal) version number of the client browser.
 MSDomVersion Gets the version of Microsoft XML Document Object Model (DOM) that the client browser supports.
 Platform Gets the name of the platform that the client uses.
 Tables Gets a value indicating whether the client browser supports HTML tables.
 Type Gets the name and major (that is, integer) version number of the client browser.
 VBScript Gets a value indicating whether the client browser supports VBScript.
 Version Gets the full (integer and decimal) version number of the client browser.
 W3CDomVersion Gets the version of the World Wide Web Consortium (W3C) XML Document Object Model (DOM) that the client browser supports.
 Win16 Gets a value indicating whether the client is a Win16-based machine.
 Win32 Gets a value indicating whether the client is a Win32-based machine.

For more information about HttpBrowserCapabilities class, click here

This code lines for ASP.NET using C# language:

 <%@ Page Language="C#" %>
<html>

 <head>
 <title>Browser Information</title>
 </head>

 <body>

 <p><font face="Arial" size="3"><b>Browser Information</b></font></p>
 <hr align="left" width="30%" color="#04ACB5">
 <div align="left">
  <table border="0" width="44%">
    <tr>
      <td width="34%"><font face="Verdana" size="2">Browser Type</font></td>
      <td width="4%"><font face="Verdana" size="2">:</font></td>
      <td width="66%"><font face="Verdana" size="2"><%= Request.Browser.Browser %></font></td>
    </tr>
    <tr>
      <td width="34%"><font face="Verdana" size="2">Version</font></td>
      <td width="4%"><font face="Verdana" size="2">:</font></td>
      <td width="66%"><font face="Verdana" size="2"><%= Request.Browser.Version %></font></td>
    </tr>
    <tr>
      <td width="34%"><font face="Verdana" size="2">ActiveX Control</font></td>
      <td width="4%"><font face="Verdana" size="2">:</font></td>
      <td width="66%"><font face="Verdana" size="2"><%= Request.Browser.ActiveXControls %></font></td>
    </tr>
    <tr>
      <td width="34%"><font face="Verdana" size="2">Java Script</font></td>
      <td width="4%"><font face="Verdana" size="2">:</font></td>
      <td width="66%"><font face="Verdana" size="2"><%= Request.Browser.JavaScript %></font></td>
    </tr>
    <tr>
      <td width="34%"><font face="Verdana" size="2">Java Applet</font></td>
      <td width="4%"><font face="Verdana" size="2">:</font></td>
      <td width="66%"><font face="Verdana" size="2"><%= Request.Browser.JavaApplets %></font></td>
    </tr>
    <tr>
      <td width="34%"><font face="Verdana" size="2">VB Script</font></td>
      <td width="4%"><font face="Verdana" size="2">:</font></td>
      <td width="66%"><font face="Verdana" size="2"><%= Request.Browser.VBScript %></font></td>
    </tr>
  </table>
 </div>
 <hr align="left" width="30%" color="#04ACB5">
 <p><font face="Times New Roman" size="2" color="#000000">Copyright &copy 2001 <a href="mailto:agusasia@yahoo.com"> Agus Kurniawan</a></font></p>

 </body>

 </html>

Save this file as detectbrowser.aspx and put on your IIS directory. Run it !!.

Reference

Microsoft Studio.NET Documentation

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder PE College
Indonesia Indonesia
He gradueted from Sepuluh Nopember Institute of Technology (ITS) in Department of Electrical Engineering, Indonesia. His programming interest is VC++, C#, VB, VB.NET, .NET, VBScript, Delphi, C++ Builder, Assembly,and ASP/ASP.NET. He's founder for PE College(www.pecollege.net), free video tutorial about programming, infrastructure, and computer science. He's currently based in Depok, Indonesia. His blog is http://geeks.netindonesia.net/blogs/agus and http://blog.aguskurniawan.net

Comments and Discussions

 
QuestionBrowser Language Pin
PrakashKick1-Oct-12 0:43
PrakashKick1-Oct-12 0:43 
QuestionDoupt urgent!!!!!!!!! Pin
hetfgfgyt3-Apr-11 21:46
hetfgfgyt3-Apr-11 21:46 
GeneralYou can also directly use. Pin
hrojasara22-Mar-11 6:37
hrojasara22-Mar-11 6:37 
GeneralGood job. Short and to the point Pin
defwebserver25-Mar-08 13:11
defwebserver25-Mar-08 13:11 
Questionbrowser detection in standalone c# applicaion Pin
code4jigar30-Jun-06 1:10
code4jigar30-Jun-06 1:10 
GeneralEnabled/Disabled Pin
Anonymous2-Jun-04 1:34
Anonymous2-Jun-04 1:34 
GeneralFind explorer status Pin
M Saad++6-Feb-04 8:50
M Saad++6-Feb-04 8:50 
GeneralRe: Find explorer status Pin
enjoycrack6-Sep-05 16:16
enjoycrack6-Sep-05 16:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.