【记录】ASP.NET MVC JsonResult JsonRequestBehavior AllowGet
JS Ajax 调用代码:
$.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返回值时的错误
【记录】ASP.NET MVC JsonResult JsonRequestBehavior AllowGet的更多相关文章
- Asp.net MVC JsonResult 忽略属性
指定 JavaScriptSerializer 不序列化公共属性或公共字段.无法继承此类. 命名空间: System.Web.Script.Serialization 程序集: System.We ...
- [转]自定义ASP.NET MVC JsonResult序列化结果
本文转自:http://blog.163.com/luckcq@yeah/blog/static/17174770720121293437119/ 最近项目中前台页面使用EasyUI的jQuery插件 ...
- [记录]ASP.NET MVC 2.0 如何使用Html.RadioButtonFor?
在MVC 2.0里支持强类型实体绑定,可以直接使用如 <%: Html.TextBoxFor(model => model.Description, new { @class=" ...
- 在ASP.NET MVC中使用Boostrap实现产品的展示、查询、排序、分页
在产品展示中,通常涉及产品的展示方式.查询.排序.分页,本篇就在ASP.NET MVC下,使用Boostrap来实现. 源码放在了GitHub: https://github.com/darrenji ...
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】
MVC 默认 Request 方式为Get. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三" ...
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)
MVC 默认 Request 方式为 Post. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三&qu ...
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)<转>
MVC 默认 Request 方式为 Post. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三&qu ...
- asp.net mvc自定义JsonResult类来防止MaxJsonLength超过限制
前不久在做一个项目的时候,我用到了mvc的webapi返回了一个大数据,结果报了500错误,如下图所示: Server Error in ‘/’ Application. Error during s ...
- ASP.NET MVC之JsonResult(六)
前言 这一节我们利用上节所讲Unobtrusive Ajax并利用MVC中的JsonResult来返回Json数据. JsonResult 上节我们利用分部视图返回数据并进行填充,当我们发出请求需要获 ...
随机推荐
- DES加密
接口等加密字段 import java.security.SecureRandom; import javax.crypto.Cipher;import javax.crypto.SecretKey; ...
- Linux 系统查看物理内存使用率的命令脚本,以百分比形式输出。
想监视系统内存?好像是没法直接得到现成的百分比的,自己取值计算一下吧 totalmem=`free -m | grep 'Mem' | awk '{print $3}'` usedmem=`free ...
- Android中获取选择图片与获取拍照返回结果差异
导语: 如今的安卓应用在选择图片的处理上大多合并使用拍照和从相册中选择这两种方式 今天在写一个这样的功能时遇到一个尴尬的问题,同样是拍照获取图片功能,在不同手机上运行的效果不一样,下面是在某型手机上测 ...
- [LintCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- hibernate中SessionFactory与Session的作用
首先,SessionFactory是线程安全的,SessionFactory用到了工厂模式. 其创建和销毁需要耗费很大的资源,所以一个应用中的一个数据库一般只对应一个sessionfactory. S ...
- *HDU 2451 数学
Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- Mimikatz 使用Tips
1.记录 Mimikatz输出: C:\>mimikatz.exe ""privilege::debug"" ""log sekurl ...
- 解决 PowerDesigner 错误 The generation has been cancelled…
在Model Settings中按照如下图设置即可.
- GridControl读取xml和保存xml
using DevExpress.XtraGrid;// ...string fileName ="c:\\XtraGrid_SaveLayoutToXML.xml"; priva ...
- 微信双开是定时炸弹?关于非越狱iOS上微信分身高危插件ImgNaix的分析
作者:蒸米@阿里移动安全 序言 微信作为手机上的第一大应用,有着上亿的用户.并且很多人都不只拥有一个微信帐号,有的微信账号是用于商业的,有的是用于私人的.可惜的是官方版的微信并不支持多开的功能,并且频 ...