The best browser detection solution in ASP.NET 4.0
Asked Answered
O

5

20

I googled this topic and I came across with three different ways to configure browser capabilities: browscap.ini, browserCaps element in web.config and .browser files in App_Browsers. I thought .browser files is the latest way, but I don't seem to find up-to-date files. But I found quite fresh browscap.ini from http://browsers.garykeith.com/downloads.asp.

My first priority is to exclude common crawlers from the visitor stats. The second priority is to detect browser and os with correct versions (e.g. Opera 11 / Win7).

Are there any libraries I could use? Is browscap.ini still a valid way and is it possible to use it without access to system files? Where can I find up-to-date .browser files?

Obadiah answered 4/3, 2011 at 9:56 Comment(1)
browsers.garykeith.com/downloads.asp not foundMarchal
O
7

I found a user agent parser from http://user-agent-string.info/ and it seems to be good enough for my purposes.

Obadiah answered 14/4, 2011 at 14:16 Comment(0)
H
8

more info : http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx Have you checked this :

    System.Web.HttpBrowserCapabilities browser = Request.Browser;
    string s = "Browser Capabilities\n"
        + "Type = "                    + browser.Type + "\n"
        + "Name = "                    + browser.Browser + "\n"
        + "Version = "                 + browser.Version + "\n"
        + "Major Version = "           + browser.MajorVersion + "\n"
        + "Minor Version = "           + browser.MinorVersion + "\n"
        + "Platform = "                + browser.Platform + "\n"
        + "Is Beta = "                 + browser.Beta + "\n"
        + "Is Crawler = "              + browser.Crawler + "\n"
        + "Is AOL = "                  + browser.AOL + "\n"
        + "Is Win16 = "                + browser.Win16 + "\n"
        + "Is Win32 = "                + browser.Win32 + "\n"
        + "Supports Frames = "         + browser.Frames + "\n"
        + "Supports Tables = "         + browser.Tables + "\n"
        + "Supports Cookies = "        + browser.Cookies + "\n"
        + "Supports VBScript = "       + browser.VBScript + "\n"
        + "Supports JavaScript = "     + 
            browser.EcmaScriptVersion.ToString() + "\n"
        + "Supports Java Applets = "   + browser.JavaApplets + "\n"
        + "Supports ActiveX Controls = " + browser.ActiveXControls 
              + "\n"
        + "Supports JavaScript Version = " +
            browser["JavaScriptVersion"] + "\n";

    TextBox1.Text = s;
Hen answered 4/3, 2011 at 10:1 Comment(1)
I've been using Request.Browser to get browser information, but I need up-to-date config files. It gives me Opera 9.80/WinNT when I test with Opera 11/Win7.Obadiah
O
7

I found a user agent parser from http://user-agent-string.info/ and it seems to be good enough for my purposes.

Obadiah answered 14/4, 2011 at 14:16 Comment(0)
M
3

Just so no one else goes down that dark path, be aware that even the jQuery team recommend that you DO NOT use jQuery.browser object:

"The $.browser property is deprecated in jQuery 1.3"

Markland answered 19/3, 2011 at 4:7 Comment(0)
H
0

The best answer is feature detection, not browser detection! This is particularly true in the day where Firefox & Chrome are putting out releases ever few months and mobile browser use is growing. Use Modernizr (http://Modernizr.com) or an equivalent library to detect the features you are interested in.

Herbartian answered 23/8, 2011 at 22:43 Comment(2)
I don't need to know if the browser supports the latest css or html5 tricks. I write about C#/.net programming and the target audience will most likely have Windows and bleeding edge browser. I'm curious to find out what were the others interested in.Obadiah
As long as browser bugs exist, I'll want to know what browser people are using. If a client calls or emails me to say the page looks broken, I'll want to know their browser to see if I can repeat it. I'd rather detect and log their browser version in advance than try to get this info from them on the phone.Macrophysics
M
-1

So far I've used http://api.jquery.com/jQuery.browser/ for client side detection.

Mikiso answered 4/3, 2011 at 10:46 Comment(2)
Its not recommended to use this. This is from the jQuery official Docs: "We recommend against using this property; please try to use feature detection instead (see jQuery.support). jQuery.browser may be moved to a plugin in a future release of jQuery."Central
Indeed, it was deprecated in v1.3 and removed entirely in v1.9.Azotobacter

© 2022 - 2024 — McMap. All rights reserved.