locked
RSS Feed Duplicates RRS feed

  • Question

  • User-617274320 posted

    I've searched and found several posts about setting up RSS Feeds and ended up using this one to create mine. 

    http://dotnetslackers.com/articles/aspnet/How-to-create-a-syndication-feed-for-your-website.aspx

    It seems to be working fine, however when I add the RSS feed to my outlook or when I refresh using Google reader i get duplicates of the articles every time. I've made sure that I am setting both the LastUpdated and PublishDate which look correct but for some reason i still get duplicates everytime i refresh (or every time i refresh and wait 60 seconds). Help would be greatly appreciated.

    Here's a temp link to the feed

    http://tayloredcom.web709.discountasp.net/Feed.aspx?FeedType=RSS

    And here's my code

    Imports System.ServiceModel.Syndication
    
    
    Partial Class Feed
        Inherits System.Web.UI.Page
    
        Enum FeedType
            RSS
            Atom
        End Enum
    
        Private _CurrentFeedType As FeedType
        Public Property CurrentFeedType() As FeedType
            Get
                Return _CurrentFeedType
            End Get
            Set(value As FeedType)
                _CurrentFeedType = value
            End Set
        End Property
    
        Private Sub LoadFeedData()
    
            Dim oBlogs As New StingrayCMS.Content.Blog
            oBlogs.LoadAll()
    
            If oBlogs.HasError = True OrElse oBlogs.Count < 1 Then
                oBlogs.Dispose()
                Exit Sub
            End If
    
            'Set Feed Type
            Select Case True
    
                Case Request.QueryString("FeedType") = "RSS"
                    _CurrentFeedType = FeedType.RSS
                    Response.ContentType = "application/rss+xml"
    
                Case Request.QueryString("FeedType") = "Atom"
                    _CurrentFeedType = FeedType.Atom
                    Response.ContentType = "application/atom+xml"
    
                Case Else 'Default to RSS
                    _CurrentFeedType = FeedType.RSS
                    Response.ContentType = "application/rss+xml"
    
            End Select
    
    
    
            'Set Syndication Variables
            Dim sSyndicationTitle As String = ""
            Dim sSyndicationDescription As String = ""
            Dim sSyndicationLink As String = ""
            Dim sSyndicationCopyright As String = ""
            Dim sSyndicationAuthorEmail As String = ""
    
            Dim oSetting As New StingrayCMS.Content.Setting()
    
            oSetting.LoadBy(StingrayCMS.Content.Setting.LookupType.Name, "Syndication Title")
            If oSetting.HasError = False AndAlso oSetting.Count > 0 Then
                sSyndicationTitle = oSetting.Value
            End If
    
            oSetting.LoadBy(StingrayCMS.Content.Setting.LookupType.Name, "Syndication Description")
            If oSetting.HasError = False AndAlso oSetting.Count > 0 Then
                sSyndicationDescription = oSetting.Value
            End If
    
            oSetting.LoadBy(StingrayCMS.Content.Setting.LookupType.Name, "Syndication Copyright")
            If oSetting.HasError = False AndAlso oSetting.Count > 0 Then
                sSyndicationCopyright = oSetting.Value
            End If
    
            oSetting.LoadBy(StingrayCMS.Content.Setting.LookupType.Name, "Syndication Author Email")
            If oSetting.HasError = False AndAlso oSetting.Count > 0 Then
                sSyndicationAuthorEmail = oSetting.Value
            End If
    
            sSyndicationLink = ConfigurationManager.AppSettings("SyndicationLandingLink")
    
            oSetting.Dispose()
    
            'Set Syndication Properties
            Dim oUtility As New StingrayCMS.Utilities.WebObject
    
            Dim oSyndicationFeed = New SyndicationFeed
            oSyndicationFeed.Title = TextSyndicationContent.CreatePlaintextContent(sSyndicationTitle)
            oSyndicationFeed.Description = TextSyndicationContent.CreatePlaintextContent(sSyndicationDescription)
            oSyndicationFeed.Links.Add(SyndicationLink.CreateAlternateLink(New Uri(sSyndicationLink)))
            oSyndicationFeed.Links.Add(SyndicationLink.CreateSelfLink(New Uri(oUtility.GetCurrentURLString)))
            oSyndicationFeed.Copyright = TextSyndicationContent.CreatePlaintextContent(sSyndicationCopyright)
            oSyndicationFeed.Language = "en-us"
    
            Dim lFeedList As New List(Of SyndicationItem)
    
            'Create Feed
            For Each oBlog In oBlogs.BlogsAsList
    
                Dim oSyndicationItem As New SyndicationItem
    
                oSyndicationItem.Title = TextSyndicationContent.CreatePlaintextContent(oBlog.Title)
                oSyndicationItem.Links.Add(SyndicationLink.CreateAlternateLink(New Uri(ConfigurationManager.AppSettings("RootSitePath") & "/" & ConfigurationManager.AppSettings("BlogRewriteDirectory") & "/" & oBlog.SeoURL)))
                oSyndicationItem.Summary = TextSyndicationContent.CreatePlaintextContent(oBlog.PreviewText)
                oSyndicationItem.PublishDate = oBlog.DateStamp
                oSyndicationItem.LastUpdatedTime = oBlog.DateStamp
    
                'Set Blog Categories
                oBlog.LoadBlogCategories()
                If oBlog.HasError = False AndAlso oBlog.BlogCategoryCount > 0 Then
    
                    For Each oBlogCategory In oBlog.BlogCategoriesAsList
                        oSyndicationItem.Categories.Add(New SyndicationCategory(oBlogCategory.Name))
                    Next
    
                End If
    
                'Set Author Info
                Dim oSyndicationAuthor As New SyndicationPerson
                oSyndicationAuthor.Email = sSyndicationAuthorEmail
                oSyndicationAuthor.Name = oBlog.Author
                oSyndicationFeed.Authors.Add(oSyndicationAuthor)
    
                lFeedList.Add(oSyndicationItem)
    
            Next
    
            oSyndicationFeed.Items = lFeedList
    
            'Write Feed
            Dim oFeedWriter As System.Xml.XmlWriter
            oFeedWriter = System.Xml.XmlWriter.Create(Response.OutputStream)
    
            Select Case _CurrentFeedType
    
                Case FeedType.RSS
                    Dim oAtomFormatter As New Atom10FeedFormatter(oSyndicationFeed)
                    oAtomFormatter.WriteTo(oFeedWriter)
    
                Case FeedType.Atom
                    Dim oRssFormatter As New Rss20FeedFormatter(oSyndicationFeed)
                    oRssFormatter.WriteTo(oFeedWriter)
    
            End Select
            oFeedWriter.Close()
    
            oBlogs.Dispose()
    
        End Sub
    
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            LoadFeedData()
        End Sub
    
    End Class
    



    Tuesday, September 18, 2012 3:52 PM

Answers

All replies