File: App_Code\RSSHandler.cs
using System;
using System.Web;
using System.Net;
using System.IO;
namespace MyNamespace
{
public class RSSHandler : IHttpAsyncHandler
{
private HttpContext _context;
private WebRequest _request;
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
_context = context;
_request = WebRequest.Create ("http://msdn.microsoft.com/asp.net/rss.xml");
return _request.BeginGetResponse(cb, extraData);
}
public void EndProcessRequest(IAsyncResult result)
{
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.");
}
}
}
Register it in your web configuration file.
File: Web.Config
If you have a news reader, such as SharpReader, then you can enter a path like the following in the reader's address bar:
http://localhost:2026/YourApp/news.rss
File: ShowRSSHandler.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Show RSS Handler