[GIS] GeoJSON Get Request MVC 4

asp.netgeojsonopenlayers-2

I'm having trouble creating an OpenLayers Vector layer with GeoJSON data in an MVC 4 application.

The GET request for my json file always comes back with a 404.3 error – page cannot be served because of the extension configuration.

I've followed every OpenLayers example creating the GeoJSON layer just as they have but I can't get mine to display. I've followed the steps in this post
Trouble displaying GeoJSON file in OpenLayers and everything besides the GeoJSON layer works great.

So in my OpenLayers.aspx page I have the following code to initialize my vector layer.

var vector = new OpenLayers.Layer.Vector("GeoJSON", {
            projection: new OpenLayers.Projection("EPSG:900913"),
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "<%:this.Url.Content("~/Content/Delta_Parcels_2008.json") %>",
                format: new OpenLayers.Format.GeoJSON({
                    internalProjection: new OpenLayers.Projection("EPSG:900913"),
                    externalProjection: new OpenLayers.Projection("EPSG:4326")
                })
            }),
            styleMap: vector_style_map
        });

any suggestions would be much appreciated. thanks.

Best Answer

IIS and IIS Express do not have the mime type for "json" by default. You need to add the mime type to your web server so it knows to server the JSON file. If you are using the built in web server (Cassini) then it does not have support and you will need to switch.

Here is how you do it:

IIS 7: http://www.uipress.com/add-json-handler-support-in-iis-7/#.UUds21eRfQM

IIS Express: http://michaellhayden.blogspot.com/2012/07/add-json-mime-type-to-iis-express.html

You can also do it in your web.config: https://stackoverflow.com/questions/5924647/setting-mime-types-using-the-asp-net-development-server