如何防止mvc上的json劫持?
[PreventHijack]
public JsonResult Check(int id)
{
return Json(id, JsonRequestBehavior.AllowGet);
}
的javascript
$.ajax({
url: "/Controller/Check?id=1",
type: "post",
success: function(data) {
}
})
我不希望任何人通过地址栏浏览这个jsonresult。 是否有可能在这里使用antiforgerytoken?
答案 0 :(得分:1)
您明确允许用户使用JsonRequestBehavior.AllowGet
浏览到该网址。如果你这样做,.NET会在点击该URL时抛出错误:This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request