Proxy.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Proxy.aspx.cs" Inherits="Proxy._Proxy" % >
The Proxy.aspx page is simply blank except for the Page tag. When passing the URL to the query string, it is important that it is URL encoded. This helps to prevent query strings of the remote site URL from interfering with the Proxy page.
Example Usage
yoursite.com/proxy.aspx?u=http%3a%2f%2fwww.google.com
Originally posted: http://www.johnchapman.name/aspnet-proxy-page-cross-domain-requests-from-ajax-and-javascript/
Add all line of code in try catch because error can occur in any line of code
protected void getWebRequest()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.msn.com");
request.Method = "GET";
request.Proxy = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string contentType = response.ContentType;
Stream content = response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
Response.ContentType = contentType;
Response.Write(contentReader.ReadToEnd());
}
catch (Exception ee)
{
Response.Write(ee.Message.ToString());
}
}