Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override X-UA-Compatible setting in web.config for specific pages and frames

I have a .Net web application that includes a web.config setting to force Internet Explorer to turn off compatibility mode and use the most recent version of IE available:

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

However, this application contains a legacy page that requires Compatibility mode. In my testing, it will only display properly when X-UA-Compatible is set to IE=5.

Is there a way to override the web.config setting for a single page?

Among the many things I have tried that have not worked:

  • Including <meta http-equiv="X-UA-Compatible" content="IE=5" /> on the page itself, as the first tag after <head>
  • Adding X-UA-Compatible:IE=5 to the response headers. Unfortunately, it also sends the X-UA-Compatible:IE=Edge header, and that one 'wins.'
  • Changing the <!DOCTYPE >. I tried all the various options.
  • Adding a comment before the DOCTYPE
  • Re-writing the page to be standards-compliant. This is obviously the best solution, but the page in question is a complex mapping application, and the re-write is going to take several months.

Update
When I called this "a complex mapping application," I should have said "a rat's nest of frames and tables." It turns out that the frames part was relevant to the solution.

like image 836
xcer Avatar asked Jul 25 '14 23:07

xcer


2 Answers

I finally got this fixed by putting this code in the Page_Load() of every page that is part of the frameset for this page (about a dozen pages in total).

Response.ClearHeaders();
Response.AddHeader("X-UA-Compatible", "IE=5");

I had been assuming that the frameset pages would inherit the setting from the main page, but apparently not. Just putting that on the main page did not work, I had to put it on every page/frame.

like image 89
xcer Avatar answered Sep 18 '22 10:09

xcer


You could try using a location tag...

<location path="YourPage.aspx">
    <system.webServer>
       <httpProtocol>
          <customHeaders>
             <add name="X-UA-Compatible" value="IE=5" />
          </customHeaders>
       </httpProtocol>
    </system.webServer>
</location>
like image 41
Erik Funkenbusch Avatar answered Sep 18 '22 10:09

Erik Funkenbusch