本文介绍了JSON allowget错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误在我们的MVC应用程序出现随机。有时候,做同样的事情也不会有时,它会。有谁知道这有什么,可能是一个简单的修复,还是做,如果这是常见的,很多你见过?什么

  System.InvalidOperationException:该请求已被封锁,因为敏感信息可能被泄露给第三方网站时,这在使用GET请求。要允许GET请求,JsonRequestBehavior设置为AllowGet。
   在System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext上下文)
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult的的ActionResult)
   在System.Web.Mvc.ControllerActionInvoker<> c__DisplayClass14.b__11()
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter过滤器,ResultExecutingContext preContext,Func`1续)
   在System.Web.Mvc.ControllerActionInvoker<方式>&c__DisplayClass14 LT;> c__DisplayClass16.b__13()
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter过滤器,ResultExecutingContext preContext,Func`1续)
   在System.Web.Mvc.ControllerActionInvoker<方式>&c__DisplayClass14 LT;> c__DisplayClass16.b__13()
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter过滤器,ResultExecutingContext preContext,Func`1续)
   在System.Web.Mvc.ControllerActionInvoker<方式>&c__DisplayClass14 LT;> c__DisplayClass16.b__13()
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext,IList`1过滤器,的ActionResult的ActionResult)
   在System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,字符串actionName)
   在System.Web.Mvc.Controller.ExecuteCore()
   在System.Web.Mvc.ControllerBase.Execute(RequestContext的的RequestContext)
   在System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext的的RequestContext)
   在System.Web.Mvc.MvcHandler<> c__DisplayClass8.b__4()
   在System.Web.Mvc.Async.AsyncResultWrapper<> c__DisplayClass1.b__0()
   在System.Web.Mvc.Async.AsyncResultWrapper<> c__DisplayClass8`1.b__7(IAsyncResult的_)
   在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   在System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult的asyncResult)
   在System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult的结果)
   在System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在System.Web.HttpApplication.ExecuteStep(IExecutionStep一步,布尔和放大器; completedSynchronously)


解决方案

回答您的问题是在堆栈跟踪。 JsonRequestBehavior到AllowGet

因此​​,在你的控制器使用它作为:

 返回JSON(数据,JsonRequestBehavior.AllowGet)

This error comes up in our MVC app randomly. Sometimes doing the same exact thing it won't sometimes, it will. Does anyone know if this has to do with anything that could be a simple fix, or if this is something common that a lot 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)
解决方案

Answer for your question was in the stack trace. "JsonRequestBehavior to AllowGet"

So use it in your Controller as:

return Json(data, JsonRequestBehavior.AllowGet)

这篇关于JSON allowget错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 17:38