Json permission error

This error appears randomly in our MVC application. Sometimes doing the same thing that it wonโ€™t, sometimes. Does anyone know if this is related to anything that could be a simple fix, or if it is something in common that many of you have seen?

System.InvalidOperationException: 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. at System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.b__11() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<>c__DisplayClass16.b__13() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<>c__DisplayClass16.b__13() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<>c__DisplayClass16.b__13() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) at System.Web.Mvc.Controller.ExecuteCore() at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.b__4() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.b__0() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 
+50
json jquery asp.net-mvc
Jan 6 2018-11-11T00:
source share
4 answers

The answer to your question was in the stack trace. "JsonRequestBehavior to AllowGet"

So use it in your controller like:

 return Json(data, JsonRequestBehavior.AllowGet) 
+117
Jan 06 2018-11-11T00:
source share

You should read http://haacked.com/archive/2009/06/24/json-hijacking.aspx/ before going around with these security controls.

If you publish only JSON data in response to the Http POST, you are not vulnerable to this attack.

You can simply annotate the JSON action with [HttpPost], and in the client do something like

 $.post('/blag/JSON', function (data) { //do something with my json data object here }); 
+21
Jun 22 '11 at 12:52
source share

It seems like you once called a controller action on an HTTP GET. To be able to return JSON results, you must use code like

 return Json(data, JsonRequestBehavior.AllowGet); 
+4
Jan 6 2018-11-11T00:
source share

 return Json(PartialView("index").ToJsonObject(this), JsonRequestBehavior.AllowGet); 
-one
Jun 23 '15 at 7:43
source share



All Articles