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)
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)