500.19 – Internal Server Error – The requested page cannot be accessed because the related configuration data for the page is invalid

Today I faced this error while trying to run a web application.

It turned out that it was occurred in a REST request to the server to retrieve a JSON file. I tried to solve this issue by first opening IIS and check the declared MIME types under the web application, then it complained that there is a duplicate entry in the web.config file.

It turned out that if the web.config file contains a declaration for the MIME type .json and under the application in IIS the MIME type is also declared, IIS will complain. I solved the issue by removing the MIME type declaration from the web.config file.

Firefox requests for XML format when performing a GET to Web API

Today while testing the Ext JS application I was writing on various browsers, something strange happened. The app works on IE and Chrome, while on Firefox it breaks.

It turns out if not configured correctly WebAPI will return data depending on the Accept HTTP header sent by browsers, and different browsers sent different HTTP Accept header.

More details in the SO answer: http://stackoverflow.com/a/31934984

Firefox prefers XML, so Web API try to serialize data in XML format to return to Firefox.

IE and Chrome doesn’t prefer one over other, so Web API chooses Json.

I solved this issue in Firefox by configuring the web api to always return JSON by adding the following line to WebApiConfig.cs

config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue(“text/html”));

Cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute ‘fileExtension’ set to ‘.json’

This issue occurred today while I was trying to run an Ext JS application from IIS, because .json files are not accepted by IIS I tried to add this file extension to the application. But instead I got a 500 error when trying to browse the application.

After some digging and searching the MIME types section of the website and all other applications, I couldn’t find the conflicting extension.

I was able to solve the issue by editing the application’s web.config file, right before the mimeMap tag, add a remove tag like following:

<staticContent>

<remove fileExtension=.json/>

<mimeMap fileExtension=.json mimeType=application/json />

</staticContent>

I still have no idea why this works, but it works.

Ext JS component cannot display json data read from proxy

Not entirely sure why, but when using ajax proxies, specifying the URL is not enough, the data won’t be displayed on lists/panels.

A reader must also be defined in the proxy, otherwise the data will not be read correctly

proxy: {
type: ‘ajax’,
url: ‘data.json’,
reader:{
type:’json’,
rootProperty: ‘DATA’
}

}

Make sure that

  • the source data is working, test using Fiddler/POSTMan/etc
  • The model’s fields match the fields in json data, case-sensitive.
  • A reader is configured in the proxy
  • rootProperty is set correctly and match the json data, case-sensitive.

 

Cannot bind multiple parameters in Web Api, cannot bind Json parameter

Simple, Web Api 1 doesn’t support multiple parameters.

Also, make sure the route config are correct so that the controller and action can be reached.

To bind Json parameter, use Content-Type: application/json in the request header, make sure the json object is the root object and the model to load from the server user properties instead of fields.