RSS Handler : HTTP Handlers « Development « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » Development » HTTP Handlers 
9. 24. 5. RSS Handler
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

<configuration>
    <system.web>

      <httpHandlers>
        <add path="*.rss" verb="*" type="MyNamespace.RSSHandler"/>
      </httpHandlers>

    </system.web>
</configuration>

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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void Page_Load()
    {
        string pagePath = Request.Url.OriginalString;
        string rssPath = Path.ChangeExtension(pagePath, ".rss");
        srcRSS.DataFile = rssPath;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show RSS Handler</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:GridView
        id="grdRSS"
        DataSourceID="srcRSS"
        AutoGenerateColumns="false"
        Runat="server">
        <Columns>
        <asp:TemplateField HeaderText="Articles">
        <ItemTemplate>
            <asp:HyperLink
                id="lnkRSS"
                Text='<%# XPath("title"%>'
                NavigateUrl='<%# XPath("link"%>'
                Runat="server" />
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>
    </asp:GridView>

    <asp:XmlDataSource
        id="srcRSS"
        XPath="//item"
        Runat="server" />
    </div>
    </form>
</body>
</html>
9. 24. HTTP Handlers
9. 24. 1. Creating HTTP Handlers
9. 24. 2. Creating a Generic Handler
9. 24. 3. HelloWorld HttpHandler (VB)
9. 24. 4. Implementing the IHttpHandler Interface
9. 24. 5. RSS Handler
9. 24. 6. Creating a Custom HTTP Handler
9. 24. 7. Log user in HttpModule
9. 24. 8. Source viewer Http Handler
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.