[GIS] Running OpenLayers in .NET 4.5 breaks

asp.netopenlayers-2visual studio

So, I'm writing an web mapping application using OpenLayers in WebForms in .NET 4.5.

It was working wonderfully until my browser upgraded to IE9. Now the JavaScript fails. After researching I found that the problem seems to be that IE9 changed how it handles certain kinds of JavaScript. So the solution, until the community can rewrite the JavaScript libraries, seems to be to have the browser run in compatibility mode. Unfortunately, I can't seem to get compatibility mode to work correctly.

Currently my application has one page and this is the header:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="AgPlaceHolder._default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>Agrilogic Place Holder</title>
<script src="OpenLayers.js"></script>
<script src="AgInit.js"></script>
<script src="AgLabels.js"></script>

<style>
    html, body
    {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
    }
</style>
</head>

It didn't work. So I found this alternative to add to the web.config file:

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

This also didn't work.

I've tried some variations I've seen used around, but none of them seem to be working. Does anyone see what I might have done wrong? Or has another solution to this problem?

Thanks.

On Edit:

I'm using OpenLayers 2.12.

The error is:

Unhandled exception at line 670, column 407 in http://localhost:57639/OpenLayers.js

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'resources': object is null or undefined

The code for setting up the map is:

map = new OpenLayers.Map({
    div: "map",
    layers: layerArray,
    controls: [
        new OpenLayers.Control.LayerSwitcher({ roundedCorner: true }),
        new OpenLayers.Control.PanZoomBar(),
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.ScaleLine({ geodesic: true }),
        new OpenLayers.Control.KeyboardDefaults(),
        new OpenLayers.Control.MousePosition({
            displayProjection: new OpenLayers.Projection("EPSG:4326"),
            numDigits: 5,
            emptyString: '',
            prefix: "x: ",
            separator: " y: "
        }),
        //new OpenLayers.Control.EditingToolbar(editableLayer),
        //new OpenLayers.Control.SelectFeature(editableLayer, { toggle: true, clickout: true }),
        //new OpenLayers.Control.DragFeature(editableLayer),
        overviewMapControl
    ]
});

The java script works fine, except for another issue I have posted a question on over in GISStackExchange, but that's not preventing the maps from showing. The problem there is I can't drag the label-points the program creates. But now with the upgrade of the browser I can't even display the maps anymore. The page just fails.

The newly built page has the same errors. When I remove Bing:

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'wrapDateLine': object is null or undefined

When I include Bing:

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'resources': object is null or undefined

I am at the mercy of your expertise.

Best Answer

So, apparently BING sends its "your key is expired" error message under status 200. OpenLayers, quite reasonably, assumed that status 200 meant "O.K." when BING meant "we're too lazy to do this correctly." Naturally, Chrome Developer Tools, FireBug, and Visual Studio did the same thing and reported no problem and until the script tried to run. So note to the next guy: open the entire response, don't believe the header.

Related Question