【记录】ASP.NET MVC JsonResult JsonRequestBehavior AllowGet
2014-12-10 14:50
295 查看
JS Ajax 调用代码:
Controller Action 代码:
注意这种实现在 ASP.NET 5 项目中,是没有任何问题的,但在 ASP.NET MVC 5 中,会报如下错误:
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.
正确代码(AllowGet):
参考:
What 'sensitive information' could be disclosed when setting JsonRequestBehavior to AllowGet
JSON Problem - JsonRequestBehavior to AllowGet.
JsonResult作为Action返回值时的错误
$.ajax({ url: "/AjaxController/GetInfoById", type: 'GET', datatype: "json", contentType: "application/json; charset=utf-8", data: { id: id }, success: function (data) { if (data) { alert(data.Id); alert(data.Title); } }, error: function (error) { $("#result_div").html(error.responseText); } });
Controller Action 代码:
[HttpGet] public async Task<JsonResult> GetInfoById(int id) { var result = await service.GetInfoById(id); return Json(result); }
注意这种实现在 ASP.NET 5 项目中,是没有任何问题的,但在 ASP.NET MVC 5 中,会报如下错误:
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.
正确代码(AllowGet):
[HttpGet] public async Task<JsonResult> GetInfoById(int id) { var result = await service.GetInfoById(id); return Json(result, JsonRequestBehavior.AllowGet); }
参考:
What 'sensitive information' could be disclosed when setting JsonRequestBehavior to AllowGet
JSON Problem - JsonRequestBehavior to AllowGet.
JsonResult作为Action返回值时的错误
相关文章推荐
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)<转>
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)<转>
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)
- 在ASP.NET MVC中json的应用(即JsonResult)
- 针对dynamic类型进行单元测试的方法(例如ASP.NET MVC中的JsonResult)
- ASP.NET MVC处理JsonResult返回时间DateTime问题
- ASP.NET MVC的JsonResult
- 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
- 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
- [转]自定义ASP.NET MVC JsonResult序列化结果
- 在ASP.NET MVC中json的应用(即JsonResult)(asp.net mvc 后台返回json数据方式 )
- Asp.net Mvc Ajax JsonResult简单使用
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 解决ASP.NET MVC(post数据)Json请求太大,无法反序列化(The JSON request was too large to be deserialized)
- ASP.NET中MVC使用AJAX调用JsonResult方法并返回自定义错误信息
- Asp.net MVC JsonResult 忽略属性
- 使用ExposedObject对Asp.net MVC中匿名类型的JsonResult做单元测试
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- Asp.net Mvc Ajax JsonResult简单使用