asp.net - How to forcefully set IE's Compatibility Mode off from the server-side? -
in domain-controlled environment i'm finding compatibility mode triggered on clients (winxp/win7, ie8/ie9) when providing x-ua tags, !doctype definition , "ie=edge" response headers. these clients have "display intranet sites in compatibility view" checkbox ticked. precisely i'm trying override.
the following documentation i've used try understand how ie decides trigger compatibility mode.
http://msdn.microsoft.com/en-us/library/ff406036%28v=vs.85%29.aspx
http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx
site owners always in control of content. site owners can choose use x-ua-compatible tag absolutely declarative how they’d site display , map standards mode pages ie7 standards. use of x-ua-compatible tag overrides compatibility view on client.
google "defining document compatibility", sadly spam engine doesn't let me post more 2 urls.
this asp .net
web app , includes following definitions on master page:
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <head> <meta http-equiv="x-ua-compatible" content="ie=edge" /> </head>
and web.config
<system.webserver> <httpprotocol> <customheaders> <clear /> <add name="x-ua-compatible" value="ie=edge" /> </customheaders> </httpprotocol> </system.webserver>
i've used fiddler check header indeed being injected correctly.
my understanding these settings should able override "display intranet sites in compatibility view" browser setting. depending on client i've found of them still trigger compatibility mode. seems down machine level rather policy group setting, since obtain different results when use same set of credentials on different clients.
disabling compatibility view settings checkbox trick. actual purpose make sure app rendered same way regardless of client settings.
any thoughts , possibly missing? possible @ force ie render pages without triggering compat mode?
thanks million,
jaume
ps: site in development , of course not in microsoft's compatibility list, i've checked in case.
google "understanding compatibility view list", sadly spam engine doesn't let me post more 2 urls.
i found problems 2 common ways of doing this:
doing custom headers (
<customheaders>
) in web.config allows different deployments of same application have set differently. see 1 more thing can go wrong, think it's better if application specifies in code. also, iis6 doesn't support this.including html
<meta>
tag in web forms master page or mvc layout page seems better above. however, if pages don't inherit these tag needs duplicated, there's potential maintainability , reliability problem.network traffic reduced sending
x-ua-compatible
header internet explorer clients.
well-structured applications
if application structured in way causes pages inherit single root page, include <meta>
tag shown in the other answers.
legacy applications
otherwise, think best way automatically add http header html responses. one way this using ihttpmodule
:
public class iecompatibilitymodedisabler : ihttpmodule { public void init(httpapplication context) { context.presendrequestheaders += (sender, e) => disablecompatibilitymodeifapplicable(); } private void disablecompatibilitymodeifapplicable() { if (isie && ispage) disablecompatibilitymode(); } private void disablecompatibilitymode() { var response = context.response; response.addheader("x-ua-compatible", "ie=edge"); } private bool isie { { return context.request.browser.isbrowser("ie"); } } private bool ispage { { return context.handler page; } } private httpcontext context { { return httpcontext.current; } } public void dispose() { } }
ie=edge
indicates ie should use latest rendering engine (rather compatibility mode) render page.
it seems http modules registered in web.config file, brings first problem. however, you can register them programmatically in global.asax this:
public class global : httpapplication { private static iecompatibilitymodedisabler module; void application_start(object sender, eventargs e) { module = new iecompatibilitymodedisabler(); } public override void init() { base.init(); module.init(this); } }
note important module static
, not instantiated in init
there 1 instance per application. of course, in real-world application ioc container should managing this.
advantages
- overcomes problems outlined @ start of answer.
disadvantages
- website admins don't have control on header value. problem if new version of internet explorer comes out , adversely affects rendering of website. however, overcome having module read header value application's configuration file instead of using hard-coded value.
- this may require modification work asp.net mvc.
- this doesn't work static html pages.
- the
presendrequestheaders
event in above code doesn't seem fire in iis6. haven't figured out how resolve bug yet.
Comments
Post a Comment