ASP.NET 4.0 中最好的浏览器检测解决方案

发布于 2024-10-20 01:05:36 字数 440 浏览 2 评论 0原文

我用 google 搜索了这个主题,发现了三种不同的方法来配置浏览器功能:browscap.ini、web.config 中的 browserCaps 元素和 App_Browsers 中的 .browser 文件。我认为 .browser 文件是最新的方式,但我似乎没有找到最新的文件。但我从 http://browsers.garykeith.com/downloads.asp

我的首要任务是从访客统计数据中排除常见的爬虫。第二个优先事项是检测具有正确版本的浏览器和操作系统(例如 Opera 11 / Win7)。

有我可以使用的库吗? browscap.ini 仍然是一种有效的方法吗?是否可以在不访问系统文件的情况下使用它?在哪里可以找到最新的 .browser 文件?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甜警司 2024-10-27 01:05:36

更多信息:http://msdn.microsoft.com/en-us/library/ 3yekbd5b.aspx
你检查过这个吗:

    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;

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;
悸初 2024-10-27 01:05:36

我从 http://user-agent-string.info/ 找到了一个用户代理解析器,它似乎足够好我的目的。

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

陌上芳菲 2024-10-27 01:05:36

为了避免其他人走上这条黑暗道路,请注意,即使 jQuery 团队也建议您不要使用 jQuery.browser 对象:

“$.browser 属性在 jQuery 1.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"

剩一世无双 2024-10-27 01:05:36

最好的答案是功能检测,而不是浏览器检测!在 Firefox 和 Firefox 出现的今天尤其如此。 Chrome 每隔几个月就会发布一次版本,并且移动浏览器的使用正在增长。使用 Modernizr (http://Modernizr.com) 或等效库来检测您感兴趣的功能。

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.

梦开始←不甜 2024-10-27 01:05:36

到目前为止,我已经使用 http://api.jquery.com/jQuery.browser/用于客户端检测。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文