二、CROS (Cross-origin Resource Sharing)

  CROS相当于一种协议,由浏览器、服务端共同完成安全验证,进行安全的跨域资源共享。对于开发人员来说就跟在本站AJAX请求一样,浏览器会自动判断是否使用CROS。

  客户端:

 <script type="text/javascript">
function TestCors() {
$.ajax({
type: "GET",
url: "http://hamp-sz-0104/MVC/Books/Test",
dataType: "json",
success: function (obj) {
alert(obj.Name);
}
})
}
</script>

  服务端:

     public class BooksController : Controller
{
public ActionResult Test()
{
return Json(new { Name = "CORS" },JsonRequestBehavior.AllowGet);
}
}

  服务端配置:需要给允许CORS请求的消息设置Access-Control-Allow-Origin header值,或使用“*”授权任何域名可访问

 <system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:3794"/>
</customHeaders>
</httpProtocol>
</system.webServer></configuration>

  若无配置,浏览器会收到如下错误提示:SEC7120: [CORS] 原点“http://localhost:3794”未在“http://hamp-sz-0104/MVC/Books/JsonpTest”的 cross-origin 资源的 Access-Control-Allow-Origin response header 中找到“http://localhost:3794”。

最新文章

  1. GO语言练习:多返回值函数
  2. Repeater分页
  3. CUDA 程序中的同步
  4. jboolean
  5. [原博客] POJ 1067 取石子游戏
  6. void (*fun)(void);什么意思?
  7. webkit内核下的mouseup后mousemove自动触发问题及解决方法
  8. 在开源中国(oschina)上创建托管项目
  9. Struts2(六) 用Struts完成客户列表显示
  10. win10只有edge浏览器能上网的解决方法
  11. notes for lxf(三)
  12. Codeup
  13. MySQL--运维内参中的binlog_summary脚本
  14. jdbc的配置(更新中)
  15. Java 如何实现在线预览文档及修改(文本文件)
  16. Postman—使用数据文件
  17. (转)web性能优化
  18. 【原创】MySQL常用脚本整理
  19. MySQL 关于索引那点事
  20. ELK Stack 5.2.2 安装文档

热门文章

  1. 436. Find Right Interval
  2. [Offer收割]编程练习赛46
  3. 骨骼蒙皮动画(SkinnedMesh Animation)的实现
  4. Inside Geometry Instancing(上)
  5. spoj3105 MOD - Power Modulo Inverted(exbsgs)
  6. Java 虚拟机(Java Virtual Machine)
  7. bzoj4563 HAOI2016放旗子
  8. Sublime text3 插件ColorPicker(调色板)不能使用快捷键
  9. IP服务-5-网络时间协议
  10. 问题: 查看某个文件的修改记录| git log 高级用法