Preferred Language:
Listing 27.19 - App_Code\RSSHandler.cs
using System;
using System.Web;
using System.Net;
using System.IO;
namespace AspNetUnleashed
{
public class RSSHandler : IHttpAsyncHandler
{
private HttpContext _context;
private WebRequest _request;
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
// Store context
_context = context;
// Initiate call to RSS feed
_request = WebRequest.Create("http://msdn.microsoft.com/asp.net/rss.xml");
return _request.BeginGetResponse(cb, extraData);
}
public void EndProcessRequest(IAsyncResult result)
{
// Get the RSS feed
string rss = String.Empty;
WebResponse response = _request.EndGetResponse(result);
using (response)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
rss = reader.ReadToEnd();
}
_context.Response.Write(rss);
}
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
throw new Exception("The ProcessRequest method is not implemented.");
}
}
}
Need ASP.NET and Visual Studio 2008 Training?
- Learn ASP.NET 3.5 from Stephen Walther, author of ASP.NET 3.5 Unleashed.
We've provided ASP.NET training for NASA, Lockheed Martin, the National Science Foundation, Verizon,
Boeing, the US House of Representatives, Kaiser, Petco, Mary Kay, and Microsoft.
Why not your company?
-
Receive a four day, hands-on, intensive workshop.
-
We fly to you, anywhere in the world.
-
We can bring our own laptops.
To learn more, visit the
Superexpert Training website.