1

I am trying to do a "If browser is IE and is less than version 9" in ASP.Net C# codebehind.

However, In chrome, the following line:

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

Outputs as "IE" & 5 respectively. Despite using Chrome v18.

What is the correct usage for getting the users browser? Or is this just my version of Chrome playing up? It's probably really simple, but I'm sure this code worked previously

The user agent is registering as: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19

JustAnotherDeveloper
  • 3,167
  • 11
  • 37
  • 68
  • 3
    Have you got the most up to date browser definition files? http://stephenwalther.com/blog/archive/2010/03/05/use-asp-net-4-browser-definitions-with-asp-net-3-5.aspx – Kevin Main May 15 '12 at 09:21
  • Just downloaded them now and replaced them on my system, Still seems to be the same. +rep for the idea though. I was unaware of this. – JustAnotherDeveloper May 15 '12 at 09:30

1 Answers1

5

I have v19 and i do see the correct value. Are you sure you don't have any emulator (user agent emulator) or something like this...

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

and this is the code for this output:

   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";
Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • User agent settings are on default, if I goto developer tools, I can force it to somehting other than Chrome, but this option is unchecked. I think it must be my version of Chrome. In theory though, the code I am using would be correct? – JustAnotherDeveloper May 15 '12 at 09:24
  • 1
    this is the proof how the world sees you. you must have a problem somewhere between – Royi Namir May 15 '12 at 09:29
  • try to clear cache , restart the iis or the vs's iis by restarting it. – Royi Namir May 15 '12 at 09:29
  • Redownloaded the latest browser definitions and registered them for both ASP 2 and 4. Reset IIS, Cleared the cache and did a complete rebuild with clean. Still flags `type` as IE5. ALso tried under IIS and IIS Express with the same issue. Tried with firefox too and it's ok. Going to go with the simple "re-install chrome" option I think. – JustAnotherDeveloper May 15 '12 at 09:59