Simplest Possible ASP.NET AJAX Proxy Page

After spending many hours trying to get the ASP.NET AJAX proxy page, I'm sure someone out there knows a simpler and simpler way.

These are the two ways I've tried:

  • The endpoint of web services.

Problem: super complex, a lot of work

  • An OnLoad handler that sucks the URL parameter and spits out the desired web page (either JSON or XML).

Problem: code is never called.

Secondary problem: to configure the proxy page, you do not need to write a bunch of code (aka, do we really need to continue to invent a really simple wheel?) And generate 2 different files (ASPX and code) / p>

What is the easiest way to make an ASP.NET AJAX proxy page?

Meta note: I understand that this step is a bit close to the topic of discussion. Alas, I cannot mark this as a matter of the community wiki. If you think this should be a wiki question, check it out for me.

+4
source share
1 answer

You can use the general HTTP handler (ashx file). Quick example:

<%@ WebHandler Language="C#" Class="Proxy" %> using System.Web; using System.Net; public class Proxy : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; using (WebClient client = new WebClient()) { context.Response.BinaryWrite(client.DownloadData(context.Request.QueryString["url"])); } } public bool IsReusable { get { return true; } } } 
+5
source

All Articles