Friday, September 6, 2013

Enable Compatibility mode in IE

Introduction
As there are new releases of IE(Internet Explorer) coming out regularly with new features and functionalities, it is not required for legacy page/site to support latest version of the browser. So, for this reason compatibility mode is been introduced in IE8 onwards.
Problem
I have an ASP.NET MVC web application, I want it to run in IE8 or IE9 compatiblity mode in IE10 as our client uses only IE8 or IE9 and we have IE10 in our work stations. Lets see how can we acheive this.
Solution
We can achieve this by setting the value of the compatiblity mode.
Web page can specify compatibility mode either by using META tag or by setting the http header, note that META tag will take precedence over http header when both are present.

Sol 1: META Tag- place the following code in head element of web page(html page)
<meta http-equiv="X-UA-Compatible" content="IE=8, IE=9"/>
it is not only applicable for IE but also for other browsers like chrome
<meta http-equiv="X-UA-Compatible" content="IE=8, IE=9, chrome=1"/>
Important to Note: META tag should be placed in head section before any script or css tag.

Sol 2: HTTP Header- We can configure our server to send a HTTP Header along with each page i.e send "X-UA-Compatibility: IE=8" HTTP header
Now, how do we achieve the same in ASP.NET MVC application?
Add the following code snippet in web.config file
<system.webServer>
    <httpProtocol>
        <customHeaders>
            <clear/>
            <add name="X-UA-Compatible" value="IE=8"/>
        </customHeaders>
    </httpProtocol>
<system.webServer>
Important to Note:
  • system.webServer tag will only be effective if your MVC3 is to run on IIS7 or later
  • If you find your <meta> tag is overridden by IE's intranet settings, this webServer setting will override the compatibility.
For more details browser compatibility mode click here.