在Angular.js中的H5页面调用Web api时跨域问题处理
来源:互联网 发布:.旅游网络销售调查 编辑:程序博客网 时间:2024/06/06 05:08
/// <summary>
/// 被请求时
/// 在Angular.js中的H5页面调用Web api时跨域问题处理
/// </summary>
/// <param name="sender">请求者</param>
/// <param name="e">参数</param>
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "AccessCode, content-type");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
注:一般在Global.asax文件中增加此代码即可!
- 在Angular.js中的H5页面调用Web api时跨域问题处理
- H5页面调用Android 端js方法阻塞问题
- 通过Web Api 和 Angular.js 构建单页面的web 程序
- angular h5项目微信页面分享不了问题
- 静态资源(JS/CSS)存储在localStorage,适用于Web移动端H5页面制作
- angular.js路由页面缓存问题
- H5页面中的定时器(setTimeout)问题
- 关于H5 web页面在ios端滑动卡顿问题
- 【Web API系列教程】1.3 — 实战:用ASP.NET Web API和Angular.js创建单页面应用程序(上)
- 【Web API系列教程】1.4 — 实战:用ASP.NET Web API和Angular.js创建单页面应用程序(下)
- require.js在angular中的应用
- H5 Canvas JS API
- web h5页面注意事项
- asp.net web页面 调用windows api
- Android中Webviw加载H5页面调用本地相机拍照并显示在H5页面上
- 引用外部.css或.js文件的路径问题--jsp或html页面或是在web项目中的引用
- angular js 页面跳转
- angular js 页面
- java.lang.VerifyError
- 【华为机试】字符串排序
- 响应式布局值之Bootstrap
- C++_多态&多态的对象模型
- H
- 在Angular.js中的H5页面调用Web api时跨域问题处理
- CXF请求失败
- union-find算法(路径压缩+加权quick-union算法 数组实现)
- 作业7C 语言
- Linux(debian)fail2ban防御工具
- 解决 AngularJs $http 发送post,get请求,SpringMvc无法接受参数的问题。
- 让iOS程序长久在后台运行
- Python学习笔记(基础知识点二)开更了~
- 一分钟简单了解Effective java