jQuery Json 允许错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4616410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Json allowget error
提问by slandau
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?
这个错误随机出现在我们的 MVC 应用程序中。有时做同样的事情,有时不会,它会。有谁知道这是否与任何可能是简单修复的事情有关,或者这是否是你们很多人都见过的常见问题?
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)
回答by Chandu
Answer for your question was in the stack trace. "JsonRequestBehavior to AllowGet"
您的问题的答案在堆栈跟踪中。“允许获取的 JsonRequestBehavior”
So use it in your Controller as:
所以在你的控制器中使用它作为:
return Json(data, JsonRequestBehavior.AllowGet)
回答by Yablargo
You should read http://haacked.com/archive/2009/06/24/json-hiHymaning.aspx/before bypassing these security controls.
在绕过这些安全控制之前,您应该阅读http://haacked.com/archive/2009/06/24/json-hiHymaning.aspx/。
If you only expose your JSON data in response to a Http POST, then you are not vulnerable to this attack.
如果您只公开 JSON 数据以响应 Http POST,那么您就不容易受到这种攻击。
You can simply annotate your JSON action with [HttpPost] and in the client do something like
您可以简单地使用 [HttpPost] 注释您的 JSON 操作,并在客户端执行类似操作
$.post('/blag/JSON', function (data) {
//do something with my json data object here
});
回答by Oleg
It seems that you call sometime the controller action per HTTP GET. To be able to return JSON results you should use code like
似乎您有时会根据 HTTP GET 调用控制器操作。为了能够返回 JSON 结果,您应该使用类似的代码
return Json(data, JsonRequestBehavior.AllowGet);
回答by Farhad Manafi
return Json(PartialView("index").ToJsonObject(this), JsonRequestBehavior.AllowGet);