1

I am using the following asp.net code to detect the browser type:

   System.Web.HttpBrowserCapabilities browser = Request.Browser;
            if (browser.Browser == "IE" && browser.MajorVersion == 7)
            {
                do stuff...
            }

I am running IE9, but when I debug, the browser.MajorVersion is always 7. What could cause this and how can I prevent it?

Starwfanatic
  • 584
  • 2
  • 13
  • 29

2 Answers2

3

Make sure that you have browser mode set to IE9 in developer tools

Developer tools

This is what MS says about doctypes source link

  1. If a webpage specifies a doctype directive and includes an X-UA-Compatible header, the header takes precedence over the directive.

  2. If the browser supports the header, but not any of the specified document modes, it will use the highest supported document mode to display the webpage.

Older versions of the browser that don't support the header use the to determine the document mode.

Internet Explorer 9 and earlier versions display webpages without directives in IE5 (Quirks) mode. As a result, we recommend all webpages specify a directive, such as the HTML5 doctype.

This flexibility allows the greatest compatibility for earlier versions of Internet Explorer that remain popular.

Note Because all supported versions of Internet Explorer (including Microsoft Internet Explorer 6) interpret the HTML5 document type as a standards mode document type, we recommend using the HTML5 document type for all webpages that don't require a different declaration. This ensures that your webpages are display in the highest available standards mode.

The X-UA-Compatible header isn't case sensitive; however, it must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other meta elements.

DotNetUser
  • 6,494
  • 1
  • 25
  • 27
1

You need to specify a specific document mode for your webpage, use the meta element to include an X-UA-Compatible header in your webpage, as shown in the following example.

<html>
  <head>
    <!-- Enable IE9 Standards mode -->
    <meta http-equiv="X-UA-Compatible" content="IE=9" >
    <title>My webpage</title>
  </head>
  <body>
      <!-- Your Content -->
  </body>
 </html> 
Dumitru Chirutac
  • 617
  • 2
  • 8
  • 28