Json allowget error

后端 未结 4 445
难免孤独
难免孤独 2021-02-03 17:34

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

相关标签:
4条回答
  • 2021-02-03 17:50

    It seems that you call sometime the controller action per HTTP GET. To be able to return JSON results you should use code like

    return Json(data, JsonRequestBehavior.AllowGet);
    
    0 讨论(0)
  • 2021-02-03 17:54

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

    If you only expose your JSON data in response to a Http POST, then you are not vulnerable to this attack.

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

    $.post('/blag/JSON', function (data) {
           //do something with my json data object here
    
    });
    
    0 讨论(0)
  • 2021-02-03 18:04

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

    So use it in your Controller as:

    return Json(data, JsonRequestBehavior.AllowGet)
    
    0 讨论(0)
  • 2021-02-03 18:11

    return Json(PartialView("index").ToJsonObject(this), JsonRequestBehavior.AllowGet);

    0 讨论(0)
提交回复
热议问题