Introduction
When alot people try to code their first AJAX code in localhost, "Access Denied" Often pop-up
. Therefore, I code up a very simple Yahoo map proxy sample to solve this problem
Background
Got this idea from the simple php proxy by Jason Levitt
Using the code
SimpleDotNetProxy.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
namespace SimpleDotNetProxy
{
public partial class simpleProxy : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string requestString = "";
string host = "http://api.local.yahoo.com/";
for (int i = 0; i < Page.Request.QueryString.Count; i++)
{
if (!Page.Request.QueryString.Keys[i].Equals("yws_path"))
{
requestString += "&" + Page.Request.QueryString.Keys[i] + "=" + Page.Request[Page.Request.QueryString.Keys[i]];
}
}
host += Page.Request["yws_path"].ToString() + requestString;
WebRequest request = WebRequest.Create(host);
WebResponse response = request.GetResponse();
Stream recieveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(recieveStream, Encoding.Default);
string content = readStream.ReadToEnd();
this.Response.Write(content);
}
}
}
Remember removing all the tag from the aspx file