1

我正在尝试在 ASP.Net C# 代码隐藏中执行“如果浏览器是 IE 并且低于版本 9”。

但是,在 chrome 中,以下行:

if (Request.Browser.Browser == "IE" && Request.Browser.MajorVersion < 9)

分别输出为“IE”和 5。尽管使用 Chrome v18。

获取用户浏览器的正确用法是什么?或者这只是我的 Chrome 版本?这可能真的很简单,但我确信这段代码以前有效

用户代理注册为: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19

4

1 回答 1

5

我有 v19,我确实看到了正确的值。你确定你没有任何模拟器(用户代理模拟器)或类似的东西......

chrome 19

Browser Capabilities
Type = Chrome19
Name = Chrome
Version = 19.0
Major Version = 19
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 = False
Supports JavaScript = 3.0
Supports Java Applets = True
Supports ActiveX Controls = False
Supports JavaScript Version = 1.7

ie 8

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 = 3.0
Supports Java Applets = True
Supports ActiveX Controls = True
Supports JavaScript Version = 1.5

这是此输出的代码:

   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";
于 2012-05-15T09:18:24.320 回答