Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

RSS

Back to Forum: Tech Off
  • User profile image
    itprochris

    I was just wondering how Channel9 does RSS. It looks like it's an aspx page with a query string. Can someone point me to a link on how to make RSS feeds with aspx pages (I have a tutorials site, I want users to be able to subscribe to rss.aspx?category=2 to get all tutorials from the second category)...

    Thanks!

  • User profile image
    Sven Groot

    Basically you just set your Response.ContentType to "text/xml", generate the RSS page from your data and return that.

    Personally, I'd use an ashx file, not an aspx file, since you don't need the Web Forms infrastructure so you can save some performce. Ashx files aren't supported by Visual Studio .Net 2003 though, but creating them by hand is pretty simple: http://www.developerfusion.co.uk/show/2516/

  • User profile image
    sbc

    I wonder why there is no documentation for ASHX and WebHandler in the SDK? Type in WebHandler and you get nothing.

    As it is not documented, then perhaps it is something that may change in the future. Or was it considered unstable or wasn't intended to be used widely.

    If I had the code:

    <%@ Page Language="C#" src="myclass.cs" Inherits="MyNamespace.MyClass" %>

    myclass.cs
    using System;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    namespace MyNameSpace
    {
        public class MyClass : Page
        {
           void Page_Load(Object sender, EventArgs e)
           {
                HttpContext.Current.Response.ContentType = "text/xml";
                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version="1.0" encoding="ISO-8859-15" ?>");
                sb.Append("<root>");
                sb.Append("<subnode>Foo</subnode>");
                sb.Append("</root>");
                HttpContext.Current.Response.Write(sb.ToString());
           }
        }
    }
    

    How would you convert it into a WebHandler / ASHX? Note: it may not be codebehind, but part of a class library.

  • User profile image
    Sven Groot

    sbc wrote:
    I wonder why there is no documentation for ASHX and WebHandler in the SDK? Type in WebHandler and you get nothing.

    As it is not documented, then perhaps it is something that may change in the future. Or was it considered unstable or wasn't intended to be used widely.

    It seems more like they just didn't get around to it. VS2005 supports ashx files and even has a template for it (it's called Generic Handler). Still not much in the way of documentation though.

    This is actual code from my website, (it can be found at http://www.obsdewilgen.nl/rss.ashx, it uses a client side stylesheet so use view source to see the xml). It uses XSLT to transform an xml file on the server into RSS. The XSLT file and data file 1 and data file 2.

    rss.ashx:
    <%@ WebHandler class="wilgen.rss_ashx" %>


    rss.ashx.vb:
    Imports System.Xml

    Public Class rss_ashx
    Implements System.Web.IHttpHandler

    Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
    Get
    Return True
    End Get
    End Property

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
    context.Response.ContentType = "text/xml"
    context.Response.AddHeader("Content-Disposition", "inline; filename=rss.xml")
    Dim Document As New XmlDocument
    Dim Transform As New Xsl.XslTransform
    Document.Load(context.Server.MapPath("data/updates.xml"))
    Transform.Load(context.Server.MapPath("xml/rss.xslt"))
    Dim ArgumentList As New Xml.Xsl.XsltArgumentList
    ArgumentList.AddExtensionObject("urn:qw-date", New DateFunctions)

    context.Response.Output.WriteLine("<?xml version=""1.0"" encoding=""utf-8""?>")
    context.Response.Output.WriteLine("<?xml-stylesheet type=""text/xsl"" href=""xml/rsspretty.xslt"" version=""1.0""?>")
    Transform.Transform(Document, ArgumentList, context.Response.Output, New XmlUrlResolver)
    End Sub
    End Class

  • User profile image
    itprochris

    Thanks!

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.