Since ASP.NET MVC2, when you try to return a Json result without additional information, you get an error:
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request.
You must now set the property JsonRequestBehavior to the value AllowGet:
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
I read on a post that this prevents hijacking.
I wanted to know if there is an equivalent with Json.Net to prevent this type of attack.
Here is my code to create the Json result:
protected JsonNetResult JsonNet(object data)
{
JsonNetResult result = new JsonNetResult();
result.Data = data;
return result;
}
And if you want to know where I found the JsonNetResult, here is a link.
Thank you very much.
You don’t need it because in the custom
JsonNetResultthat you have shown there’s no such test. So you will never get an exception like the one you would get with the standardJsonResultif you invoke the action with GET.If you wanted you could implement exactly the same property on your custom
JsonNetResultproperty.and if you wanted to explicitly allow this for a particular action: