Reputation:
Running in IIS Express, none of these issues exist, it is only using release IIS where this becomes an issue.
I have 4 Ajax calls to retrieve data from the server, they are all identical. One of them refuses to work, claiming that
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.
This is incorrect, all functions returning data are returning data as follows:
return Json(clients, JsonRequestBehavior.AllowGet);
The Ajax calls all look like this:
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json',
url: './Updater/getClientsInfo',
data: {},
success: function (response) {
clientinfo = response;
processUpdate();
}
});
I believe it is a configuration issue as it was working fine until I came back in today.
Edit:
I disabled IIS on this machine and re-enabled it and I'm getting Windows errors while trying to enable Windows features, so there's obviously something going on with this Windows install. I'll have to troubleshoot that first as I suspect the code itself may be unrelated.
Upvotes: 2
Views: 219
Reputation: 10604
If you execute via a GET request and have an error handler set up to catch errors but forget to allow GET requests inside the catch, you'll get this error as well. I just ran into this where I had the following
public JsonResult GetCustomer(string id) {
try {
var customerRepository = new CustomerRepository();
return this.Json(new JsonMessage(true, customerRepository.GetCustomer(id)), JsonRequestBehavior.AllowGet);
} catch (Exception ex) {
LogException(ex);
return this.Json(new JsonMessage(false, ex.ToString()));
}
}
The problem was in the catch. Without the following, the server would prevent the error from being sent back
return this.Json(new JsonMessage(false, ex.ToString()), JsonRequestBehavior.AllowGet);
Upvotes: 1