Click here to Skip to main content
Click here to Skip to main content
Go to top

Detect the browser using ASP.NET and C#

, 19 Dec 2001
Rate this:
Please Sign up or sign in to vote.
A Simple ASP.NET program for detecting browser type that clients use

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

Share

About the Author

Agus Kurniawan
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 PinmemberPrakashKick1-Oct-12 0:43 
QuestionDoupt urgent!!!!!!!!! Pinmemberhetfgfgyt3-Apr-11 21:46 
GeneralYou can also directly use. Pinmemberhrojasara22-Mar-11 6:37 
GeneralGood job. Short and to the point Pinmemberdefwebserver25-Mar-08 13:11 
Questionbrowser detection in standalone c# applicaion Pinmembercode4jigar30-Jun-06 1:10 
GeneralEnabled/Disabled PinsussAnonymous2-Jun-04 1:34 
GeneralFind explorer status PinmemberM Saad++6-Feb-04 8:50 
GeneralRe: Find explorer status Pinmemberenjoycrack6-Sep-05 16:16 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 20 Dec 2001
Article Copyright 2001 by Agus Kurniawan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid