browser detection not working with changing IE browser document mode

Posted on 2014-07-15
Last Modified: 2014-07-15
I have to include an additional js script for IE7.  I am using the IE7 developer tools to test different browsers.  If you open dev tools (press F12), then there is a tab where you can switch between IE9, 8, 7.  

No matter what this setting is on, I get the same info in C# using the function below.  (For some reason it always shows IE7.  When I try to find the version using JavaScript, I see the same version (9.0) no matter what the switch is on.

Question: How can I detect the browser and test using the IE document mode tab?

Output from js
LOG: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MS-RTC LM 8; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; InfoPath.2)

Open in new window

Output from C#
Browser Capabilities
Type = IE7
Name = IE
Version = 7.0
Major Version = 7
Minor Version = 0
Platform = WinNT
Is Beta = False
Is Crawler = False
Is AOL = False
Is Win16 = False
Is Win32 = True
Supports Frames = True
Supports Tables = True
Supports Cookies = True
Supports VBScript = True
Supports JavaScript = 1.2
Supports Java Applets = True
Supports ActiveX Controls = True

Open in new window

public string GetBrowserInfo()
    System.Web.HttpBrowserCapabilities browser = Request.Browser;
    string browserString = "Browser Capabilities<br>"
        + "Type = " + browser.Type + "<br>"
        + "Name = " + browser.Browser + "<br>"
        + "Version = " + browser.Version + "<br>"
        + "Major Version = " + browser.MajorVersion + "<br>"
        + "Minor Version = " + browser.MinorVersion + "<br>"
        + "Platform = " + browser.Platform + "<br>"
        + "Is Beta = " + browser.Beta + "<br>"
        + "Is Crawler = " + browser.Crawler + "<br>"
        + "Is AOL = " + browser.AOL + "<br>"
        + "Is Win16 = " + browser.Win16 + "<br>"
        + "Is Win32 = " + browser.Win32 + "<br>"
        + "Supports Frames = " + browser.Frames + "<br>"
        + "Supports Tables = " + browser.Tables + "<br>"
        + "Supports Cookies = " + browser.Cookies + "<br>"
        + "Supports VBScript = " + browser.VBScript + "<br>"
        + "Supports JavaScript = " +
            browser.EcmaScriptVersion.ToString() + "<br>"
        + "Supports Java Applets = " + browser.JavaApplets + "<br>"
        + "Supports ActiveX Controls = " + browser.ActiveXControls
                + "<br>";
    return browserString;

Open in new window

Question by:jackjohnson44
    1 Comment

    Accepted Solution

    I found the issue.  There are two buttons on the developer tools.  Browser Mode is sent to the server.  Document Mode is on the client.  If you change Browser Mode, you can detect it in C#, Document mode you can't.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now