【记录】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 上节我们利用分部视图返回数据并进行填充,当我们发出请求需要获 ...
随机推荐
- Windows下ActiveMQ下载、安装部署
1.下载:http://activemq.apache.org/download.html 最新Windows版本 2.安装 (1) 首先配置JAVA环境变量 JAVA_HOME=D:\Progr ...
- indexOf、instanceOf、typeOf、valueOf详解
1.indexOf() 该方法用来返回某个指定的字符串值在字符串中首次出现的位置. 语法:indexOf(searchvalue,fromindex);两个参数,参数一表示查询的字符串值,参数二可选表 ...
- myeclipse tomcat内存溢出解决方法
Tomcat直接启动正常,通过myeclipse启动tomcat内存溢出.MyEclipse启动Tomcat无视catalina.bat中设置内存大小的问题.在 tomcat的catalina.bat ...
- 判断是否为mac电脑 、还是windows操作系统
/** * 是否为mac系统(包含iphone手机) * */ var isMac = function() { return /macintosh|mac os x/i.test(navigator ...
- Spket在Eclipse下的安装和配置(图文教程)
一.Spket简介 Spket是一个RIA的开发工具,具有代码自动完成.语法高亮.内容概要等功能,可以帮助开发人员高效的编写JavaScript程序. 效果图: 二.安装Spket 1.去官网(htt ...
- 安卓 自定义AlertDialog对话框(加载提示框)
AlertDialog有以下六种使用方法: 一.简单的AlertDialog(只显示一段简单的信息) 二.带按钮的AlertDialog(显示提示信息,让用户操作) 三.类似ListView的Aler ...
- 文件过滤驱动框架Minispy解析一
因工作需要,研究minispy文件过滤框架,上图为我整理出的其内核部分代码的逻辑.
- 安装mysql
查看已安装的mysql,并删除它们 rpm -qa|grep -i mysql rpm -e --nodeps filename 如果重装mysql,查找安装mysql产生的文件,并删除它们 find ...
- 基于腾讯手Q样式规范Frozen UI
Frozen UI是一个开源的简单易用,轻量快捷的移动端UI框架.基于手Q样式规范,选取最常用的组件,做成公用离线包减少请求,升级方式友好,文档完善,目前全面应用在腾讯手Q增值业务中. css组件包括 ...
- MyBatis(增删改查)
1.工程中引入包: mybatis-3.2.7.mysql-connector-java-5.1.22-bin 2.添加配置文件: <?xml version="1.0" e ...