【.Net码农】使用ashx解决ajax跨域访问的问题
2016-02-15 10:29
274 查看
http://www.xuebuyuan.com/222885.html
由于跨域访问是被IE的安全访问拒绝掉的
需要使用web代理
新建一个proxy.ashx文件
在proxy.ashx里建一个webservice
代码如下:
由于跨域访问是被IE的安全访问拒绝掉的
需要使用web代理
新建一个proxy.ashx文件
在proxy.ashx里建一个webservice
代码如下:
[WebService(Namespace="http://temouri.org//")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Proxy:IHttpHandler { public void ProcessRequest(HttpContext context) { string url = context.Request.QueryString["url"]; WebRequest request = HttpWebRequest.Create(url); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); context.Response.ContentType = response.ContentType; context.Response.Write(reader.ReadToEnd()); reader.Close(); stream.Close(); response.Close(); } }调用: window.location = "proxy.ashx?url=http://www.baidu.com";
相关文章推荐
- 程序员的出路之一
- 面试谈薪的5个参考答案
- android面试题目
- 前端面试题:写出删除非空数组最后一个元素并使数组长度减一的几种方法
- 一道常被人轻视的web前端常见面试题(JS)
- 有一种情怀只属于程序员
- 关于App程序员泡沫
- 程序员新人,如何在复杂代码中找 bug?
- 你是个成熟的职场人么?
- bigdata hadoop 面试问题一
- To Java程序员:切勿用普通for循环遍历LinkedList
- Atitit. 如何判断软件工程师 能力模型 程序员能力模型 项目经理能力模型
- Atitit. 如何判断软件工程师 能力模型 程序员能力模型 项目经理能力模型
- Atitit. 如何判断软件工程师 能力模型 程序员能力模型 项目经理能力模型
- 面试笔试杂项积累-leetcode 306-310
- 面试笔试杂项积累-leetcode 301-305
- iOS面试题四
- web前端职业规划(转)
- iOS面试题二
- iOS面试题一