This project is read-only.

Project Description
Project demonstrates simple implementation of server-side Web Browser's type/capability detection in ASP.NET 2.0+, written in C# with little Java scripting.

Proper detection of the Web Browsers type and capabilities is rather important from the end-users and developers prospective as well. Modern Web-based "thin client" applications are essentially Platform/OS independent as the Browsers are gradually becoming a surrogate/“virtual” OS for online applications. The differences between Browsers, rooted in either branding or versioning create a Browser compatibility issues, which could cause some Web applications to run incorrectly if the compatibility requirements were not met.

Simple Browser-detection feature could be added to ASP.NET web applications in order to resolve potential compatibility issues and also to help the tech support folks to perform the remote troubleshooting based on the clients' feedback regarding the Browser they use. Project demonstrates simple implementation of server-side Browser type/capabilities detection feature, written in C# with just a little of client-side Java scripting, added to the in ASP.NET 2.0+ web page for better responsiveness and interactivity. The same level of user experince, regarding responsiveness/interactivity, could be achieved by using either ASP.NET AJAX or Microsoft Sliverlight™ RIA technology set instead of JavaScript.

Working DEMO is available at: (refer to the button control named “Check your Browser” located at Home page central panel)

Project contains:

1. Class Module "BrowserInfo.cs" to be placed in AppCode directory (ASP.NET 2.0+)_
2. Default Web page "Default.aspx" to be placed in Application root directory (ASP.NET 2.0+)
3. Sample screenshot demonstrating Browser info "Browser-info-sample-screenshot.jpg" to be placed in Application root directory (ASP.NET 2.0+)

The core functionality is encapsulated in class module "BrowserInfo.cs" shown below:

// Module           :   BrowserInfo.cs
// Author           :   Alexander Bell
// Copyright        :   2008-2009 Infosoft International Inc
// Date Created     :   01/15/2008
// Last Modified    :   10/08/2009
// Description      :   Get Browser info

// DISCLAIMER: This Application is provide on AS IS basis without any warranty

using System;
using System.Web;

/// <summary>Server sider Browser detection: ASP.NET 2.0</summary> 
public static class InfosoftBrowserInfo
    #region Get Browser capabilities

    /// <summary>Browser capabilities: 2D array of Name/Values</summary>
    public static string[,] BrowserAttributes
            string _agent = String.Empty;

            if (HttpContext.Current == null) return null;

                // detailed string describing some of browser capabilities
                _agent = HttpContext.Current.Request.UserAgent;

                // browser capabilities object
                HttpBrowserCapabilities _browser = HttpContext.Current.Request.Browser;

                // browser capabilities (properties) 2D array of strings, Name/Value
                string[,] arrFieldValue = 
                    //"Major Version",
                    //"Minor Version",
                    "ECMA Script Version",
                    "Is Mobile Device",
                    "Is Beta",
                    //"Is Crawler",
                    //"Is AOL",
                    "Is Win16",
                    "Is Win32",
                    "Supports Frames",
                    "Supports Tables",
                    "Supports Cookies",
                    "Supports CSS",
                    "Supports VB Script",
                    "Supports JavaScript",
                    "Supports Java Applets",
                    "Supports ActiveX Controls",
                    "Supports CallBack",
                    "Supports XMLHttp",
                    "User Agent Details"
                    (_agent.ToLower().Contains("chrome"))? "Chrome" :_browser.Browser,
                    (_agent.ToLower().Contains("chrome"))? "See User Agent Details below" :_browser.Version,
                    (_browser.IsMobileDevice)? "YES": "NO",
                    (_browser.Beta)? "YES": "NO",
                    (_browser.Win16)? "YES": "NO",
                    (_browser.Win32)? "YES": "NO",
                    (_browser.Frames)? "YES": "NO",
                    (_browser.Tables)? "YES": "NO",
                    (_browser.Cookies)? "YES": "NO",
                    (_browser.SupportsCss)? "YES": "NO",
                    (_browser.VBScript)? "YES": "NO",
                    (_browser.JavaScript)? "YES": "NO",
                    (_browser.JavaApplets)? "YES": "NO",
                    (_browser.ActiveXControls)? "YES": "NO",
                    (_browser.SupportsCallback)? "YES": "NO",
                    (_browser.SupportsXmlHttp)? "YES": "NO",


                return arrFieldValue;
            catch { return null; }

    /// <summary>JavaScript string to containing Browsers capabilities</summary>
    public static string BrowserJavaScript
            // return string contains JavaScript
            string MsgBrowser = String.Empty;

            string[,] arrBrowser = BrowserAttributes;
            if (arrBrowser == null) return String.Empty;

                // pop-up message using JavaScript:alert function
                MsgBrowser = "javascript:alert('Your Browser properties: \\n";

                for (int i = 0; i < arrBrowser.GetLength(1); i++)
                { MsgBrowser += "\\n" + arrBrowser[0, i] + " : " + arrBrowser[1, i]; }

                return MsgBrowser += "')";
            catch { return String.Empty; }

Sample Web Page contains a single Button1 control with "onclick" even handler added as shown below:

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="">
<head runat="server">

    <title>Browser Detection } Infosoft International Inc</title>
    <script runat="server">
        private string _browser;

        protected void Page_PreInit(object sender, EventArgs e)
        {_browser = InfosoftBrowserInfo.BrowserJavaScript;}

        protected void Page_Load(object sender, EventArgs e)
        { Button1.Attributes.Add("onclick", _browser);}

    <form id="form1" runat="server">
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get Browser Info" />
        <br />
        <br />
        <br />
        <br />
        <img src="Browser_info_sample_screenshot.jpg" />

Sample message screenshot, displaying the Browser capabilities:

Fig.1. Sample screenshot

.NET ASP.NET Browser C# RIA JavaScript AJAX Sliverlight™ IE FireFox Safari Chrome

Last edited Feb 18, 2015 at 2:31 AM by DrABELL, version 16