ASP.net (IIS): IE8 - Compatibility view

February 10, 2011 by ASP.NET   IIS  

Internet explorer 8 adheres to industry standards (W3C) a lot more than previous versions of the browser - unfortunately it comes with a price (e.g. with regards to how IE renders your website(s)).

Microsoft did however think about this problem and introduced what they call "compatibility view", basically we've got a toggle button in the browser, like seen in the following image:



When we press the button, the site renders using the IE7 engine (solving our immediate problem).



It would however make a lot more sense if the visitor of the website didn't need to press the button, for that reason we can put the following meta tag into our website.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
Note that this tag needs to appear before any other element inside the html page's head tag (except the title and other meta tags, else the browser will simply ignore it), you will notice the "compatibility view" button disappearing - the visitor can't disable compatibility.



I did however see an interesting issue while settings emulation on one of our ASP.NET projects - since we've got a server side head tag, it won't necessarily be possible to always place the meta tag we're its supposed to be.

We can luckily additionally set compatibility via the web.config like this:

<system.webServer>
	<httpProtocol>
		<customHeaders>
			<clear />
			<add name="X-UA-Compatible" value="IE=EmulateIE7" />
		</customHeaders>
	</httpProtocol>
</system.webServer>

This causes IIS to automatically pass emulation via HTTP response header across all pages.

Additional Reading:
http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx
http://msdn.microsoft.com/en-us/cc817572.aspx
http://msdn.microsoft.com/en-us/cc817573.aspx


Leave a Comment