在Angular.js中的H5页面调用Web api时跨域问题处理
2017-08-01 15:49
316 查看
/// <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时跨域问题处理
/// </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时跨域问题处理
- 在Angular.js中的H5页面调用Web api时跨域问题处理
- web api 初体验 解决js调用跨域问题
- web api 初体验 解决js调用跨域问题
- iframe 大数据量传参 本地能调用远程页面 不存在跨域问题 js组件调用原理
- web api 初体验 解决js调用跨域问题
- H5页面调用Android 端js方法阻塞问题
- 巧妙解决js内容调用导致页面加载慢的问题
- 关于JS跨域刷新父页面的问题 .
- 页面编码与调用的js文件编码不同导致乱码的处理
- 异步加载页面,页面中的js的调用问题
- ajax读取页面调用JS函数问题
- IE8下,js调用另一页面js方法,不能alert问题
- 静态页面调试JS出现跨域问题
- js页面处理常见问题
- asp页面 在ajax 中 调用 前台 js代码的问题
- js在html文件中调用ActiveXObject对象成功,在jsp页面调用错误问题
- Js 跨域调用问题
- 转载:Js 跨域调用问题
- 浅谈jsp页面中调用js文件的中文乱码问题