Search code examples
javascriptasp.net-mvccesiumjs

ASP.net mvc application hosted on server fails to load cesium map resource


We have a MVC application in which we have been using Cesium maps through internet and everything was working fine, but now we are using maps locally. The local maps seems to works with deve environment (Visual Studio) but it fails to load certain resources when we host the application. We get the following errors in browser console:-

localhost/MyApp/Scripts/Cesium/Assets/approximateTerrainHeights.json Failed to load resource: the server responded with a status of 404 (Not Found)

localhost/MyApp/Scripts/Cesium/Assets/IAU2006_XYS/IAU2006_XYS_15.json Failed to load resource: the server responded with a status of 404 (Not Found)

Here is the code snippet

    var localMap = Cesium.createTileMapServiceImageryProvider({
        url: Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
    });

    var esri = new Cesium.ArcGisMapServerImageryProvider({
    url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
});

// Creating Cesium Viewer Object
var viewer = new Cesium.Viewer('cesiumContainer', {
    imageryProvider: localMap,
    resolutionScale: 0.5,
    baseLayerPicker: false,
    timeline: false,
    navigationHelpButton: false,
    animation: false,
    infoBox: false,
    sceneMode: Cesium.SceneMode.SCENE3D,
    sceneModePicker: false,
    selectionIndicator: false,
    homeButton: false,
    geocoder: false
    /*contextOptions: {
        webgl: {
            failIfMajorPerformanceCaveat: false
        }
    }*/
});

I have gone through various posts, and I know how routing works in MVC, in other instances where I was calling controllers actions I was using Url.Action(), something like:-

@Html.Hidden("URL_GetTileJson", Url.Action("GetTileJson", "JsonController"))

But when I try similar solution for above errors, it doesn't work either.

Any help/suggestions will be greatly appreciated


Solution

  • By default, IIS won't serve file extensions that it doesn't recognize. In your case you need to add a mapping for .json files. Add the following configuration to your application's web.config file (merging into your existing config)

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <staticContent>
                <remove fileExtension=".json" />
                <mimeMap fileExtension=".json" mimeType="application/json" />
            </staticContent>
        </system.webServer>
    </configuration>
    

    In the Cesium repository, we have a sample web.config that contains a larger list of useful file extensions and mime types:

    https://github.com/AnalyticalGraphicsInc/cesium/blob/master/web.config