HTTPModule to generate RSS Feed

  • Thread starter Van den Driessche Willy
  • Start date
V

Van den Driessche Willy

I am writing a HTTP Module to generate an RSS feed for certain requests. For the moment everything is hardcoded and my code looks like (the idea is - for the moment to generate the RSS feed on the fly for every request - caching is another worry for later):
Public Class rssHTTPModule

Implements System.Web.IHttpModule

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

End Sub

Public Sub Init(ByVal Application As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init

AddHandler Application.BeginRequest, AddressOf ApplicationBeginRequest

End Sub

Private Sub ApplicationBeginRequest(ByVal objSender As Object, ByVal e As System.EventArgs)

Dim app As HttpApplication = CType(objSender, HttpApplication)

Dim context As HttpContext = app.Context

Dim req As String = context.Request.Path

Dim localPath As String = context.Server.MapPath(req)

If Not (System.IO.File.Exists(localPath)) Then

If localPath.EndsWith("xml", StringComparison.InvariantCultureIgnoreCase) Then



Dim objStream As New System.Web.UI.HtmlTextWriter(context.Response.Output)

objStream.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")

objStream.AddAttribute("version", "2.0")

objStream.RenderBeginTag("rss")

objStream.RenderBeginTag("channel")

objStream.RenderBeginTag("title")

objStream.Write("test")

objStream.RenderEndTag()

objStream.RenderBeginTag("description")

objStream.Write("beschrijving")

objStream.RenderEndTag()

objStream.RenderBeginTag("language")

objStream.Write("en-us")

objStream.RenderEndTag()

objStream.RenderEndTag() ' channel

objStream.RenderEndTag() ' rss

objStream.Flush()

objStream.Close()

app.Response.StatusCode = 200

app.Response.StatusDescription = "OK"

app.CompleteRequest()

End If

End If

End Sub

End Class

What I want (to start with) is to be able to fire a request to my server www.myServer.com/jef.xml and make sure I generate the XML that has to be returned. Unfortunately, I am not able to do this. My current code is lacking something crucial. (If I execute my current code, IE explorer automatically opens a new favorite box and sharpreader just stops)
 
C

clintonG

After trying to read this news article I realized you need to go to
http://www.stevemiller.net and get his free PureText tool which removes
formatting from text copied to the clipboard so it can be pasted as ASCII
text. Its a great tool that sits in the task tray.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W


message I am writing a HTTP Module to generate an RSS feed for certain requests.
For the moment everything is hardcoded and my code looks like (the idea is -
for the moment to generate the RSS feed on the fly for every request -
caching is another worry for later):
Public Class rssHTTPModule
Implements System.Web.IHttpModule
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
Public Sub Init(ByVal Application As System.Web.HttpApplication) Implements
System.Web.IHttpModule.Init
AddHandler Application.BeginRequest, AddressOf ApplicationBeginRequest
End Sub
Private Sub ApplicationBeginRequest(ByVal objSender As Object, ByVal e As
System.EventArgs)
Dim app As HttpApplication = CType(objSender, HttpApplication)
Dim context As HttpContext = app.Context
Dim req As String = context.Request.Path
Dim localPath As String = context.Server.MapPath(req)
If Not (System.IO.File.Exists(localPath)) Then
If localPath.EndsWith("xml", StringComparison.InvariantCultureIgnoreCase)
Then
Dim objStream As New System.Web.UI.HtmlTextWriter(context.Response.Output)
objStream.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
objStream.AddAttribute("version", "2.0")
objStream.RenderBeginTag("rss")
objStream.RenderBeginTag("channel")
objStream.RenderBeginTag("title")
objStream.Write("test")
objStream.RenderEndTag()
objStream.RenderBeginTag("description")
objStream.Write("beschrijving")
objStream.RenderEndTag()
objStream.RenderBeginTag("language")
objStream.Write("en-us")
objStream.RenderEndTag()
objStream.RenderEndTag() ' channel
objStream.RenderEndTag() ' rss
objStream.Flush()
objStream.Close()
app.Response.StatusCode = 200
app.Response.StatusDescription = "OK"
app.CompleteRequest()
End If
End If
End Sub
End Class
What I want (to start with) is to be able to fire a request to my server
www.myServer.com/jef.xml and make sure I generate the XML that has to be
returned. Unfortunately, I am not able to do this. My current code is
lacking something crucial. (If I execute my current code, IE explorer
automatically opens a new favorite box and sharpreader just stops)
 
V

Van den Driessche Willy

Thnk you but this doesn't exactly solve my problem. The formatted code was
intentional.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top