You need to add a Generic Handler and then use the following code
<%@ WebHandler Language="C#" Class="RSS_CS" %>
using System;
using System.Web;
using System.Xml;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public class RSS_CS : IHttpHandler
{
public void ProcessRequest (HttpContext context) {
BuildXml(context);
}
private void BuildXml(HttpContext context)
{
using (XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))
{
DataTable dt = GetData("SELECT * FROM Channel WHERE Id = 1");
writer.WriteStartDocument();
writer.WriteStartElement("rss");
writer.WriteAttributeString("version", "2.0");
writer.WriteStartElement("channel");
writer.WriteElementString("title", dt.Rows[0]["Title"].ToString());
writer.WriteElementString("link", dt.Rows[0]["Link"].ToString());
writer.WriteElementString("description", dt.Rows[0]["Description"].ToString());
writer.WriteElementString("copyright", dt.Rows[0]["Copyright"].ToString());
dt = GetData("SELECT * FROM Feeds");
foreach (DataRow dr in dt.Rows)
{
writer.WriteStartElement("item");
writer.WriteElementString("title", dr["Title"].ToString());
writer.WriteElementString("description", dr["Description"].ToString());
writer.WriteElementString("link", dr["Link"].ToString());
writer.WriteElementString("guid", dr["Id"].ToString());
writer.WriteElementString("pubDate", Convert.ToDateTime(dr["PublishedDate"]).ToString("dd/MM/yyyy"));
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
private DataTable GetData(string query)
{
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
}
}
}
return dt;
}
public bool IsReusable {
get {
return false;
}
}
}
Database SQL
USE [master]
GO
/****** Object: Database [RSSFeeds] Script Date: 2/10/2014 1:12:24 PM ******/
CREATE DATABASE [RSSFeeds]
GO
USE [RSSFeeds]
GO
/****** Object: Table [dbo].[Channel] Script Date: 2/10/2014 1:12:03 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Channel](
[Id] [int] NOT NULL,
[Title] [varchar](200) NOT NULL,
[Description] [varchar](500) NOT NULL,
[Link] [nvarchar](50) NOT NULL,
[Copyright] [nvarchar](100) NOT NULL,
CONSTRAINT [PK_Channel] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [RSSFeeds]
GO
/****** Object: Table [dbo].[Feeds] Script Date: 2/10/2014 1:12:16 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Feeds](
[Id] [uniqueidentifier] NOT NULL,
[ChannelId] [int] NOT NULL,
[Title] [varchar](200) NOT NULL,
[Description] [varchar](1000) NOT NULL,
[Link] [nvarchar](200) NOT NULL,
[PublishedDate] [datetime] NOT NULL,
CONSTRAINT [PK_Feeds] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Feeds] WITH CHECK ADD CONSTRAINT [FK_Feeds_Channel] FOREIGN KEY([ChannelId])
REFERENCES [dbo].[Channel] ([Id])
GO
ALTER TABLE [dbo].[Feeds] CHECK CONSTRAINT [FK_Feeds_Channel]
GO
INSERT INTO Channel VALUES
(1, 'ASPSnippets RSS Feed', 'Latest additions to the content that appears on ASPSnippets.', 'http://www.aspsnippets.com/Feeds.ashx', '© 2014, www.aspsnippets.com. All rights reserved.')
GO
INSERT INTO Feeds VALUES
(NEWID(), 1, 'Validate Repeater with CheckBox (at least one checked) using JavaScript in ASP.Net',
'Here Mudassar Ahmed Khan how to validate CheckBoxes inside Repeater and perform at least one checked validation using JavaScript in ASP.Net.'
,'http://aspsnippets.com/Articles/Validate-Repeater-with-CheckBox-at-least-one-checked-using-JavaScript-in-ASPNet.aspx',
'2014-03-09')
GO
INSERT INTO Feeds VALUES
(NEWID(), 1, 'Implement Role based security using Forms Authentication in ASP.Net',
'Here Mudassar Ahmed Khan has explained how to implement Role based security and page access using Forms Authentication in ASP.Net.'
,'http://aspsnippets.com/Articles/Implement-Role-based-security-using-Forms-Authentication-in-ASPNet.aspx',
'2014-03-03')
GO
INSERT INTO Feeds VALUES
(NEWID(), 1, 'Simple Form based authentication example in ASP.Net',
'Here Mudassar Ahmed Khan has explained with example how to implement simple Form based authentication using Login page and Login control in ASP.Net using C# and VB.Net.'
,'http://aspsnippets.com/Articles/Simple-Form-based-authentication-example-in-ASPNet.aspx',
'2014-03-03')