Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up with this. Please comment or edit the post if you find any error or better way to do it.</p> <h2>RssController</h2> <pre><code>Imports System.ServiceModel.Syndication Imports System.Xml Imports System.Web.HttpContext Function MasterRSS() Dim baseURL As String = "http://www.mysite.com" Dim feed As New SyndicationFeed("MySite - Master RSS", "", New Uri(baseURL)) ''//Add a custom attribute. Dim xqName As New XmlQualifiedName("CustomAttribute") feed.AttributeExtensions.Add(xqName, "Value") Dim sp As New SyndicationPerson("jerry@mysite.com", "Jerry Seinfeld", "http://Jerry.blog.com") feed.Authors.Add(sp) Dim category As New SyndicationCategory("Category") feed.Categories.Add(category) feed.Contributors.Add(New SyndicationPerson("cosmo@mysite.com", "Cosmo Kramer", "http://kramer.blog.com")) feed.Copyright = New TextSyndicationContent("MySite 2008") feed.Description = New TextSyndicationContent("My description") ''//Add a custom element. Dim doc As New XmlDocument() Dim feedElement As XmlElement = doc.CreateElement("CustomElement") feedElement.InnerText = "Some text" feed.ElementExtensions.Add(feedElement) feed.Generator = "Custom" feed.Id = "MySiteFeedID" feed.ImageUrl = New Uri("http://www.mysite.com/content/images/logo.png") ''//Items Dim ModifiedSince As Date If Not Date.TryParse(Current.Request.Headers("If-Modified-Since"), ModifiedSince) Then ModifiedSince = Date.Today.AddDays(-30) ''//Or whatever make sense to you. Else ModifiedSince.AddMinutes(-5) ''//Just in case, we do not want to miss any item. End If ''//the list of items. Dim items As New List(Of SyndicationItem)() Dim db As New mainDataContext Dim textContent As TextSyndicationContent, Item As SyndicationItem ''//Then send the list of post, comments, whatever. Dim Posts = (From p In db.Posts Where c.Date &gt;= ModifiedSince Order By p.Date Descending) For Each Post In Posts Dim sb As New StringBuilder sb.AppendFormat("&lt;p&gt;{0}&lt;/p&gt;", Post.FullText) textContent = New TextSyndicationContent(sb.ToString, TextSyndicationContentKind.Html) Item = New SyndicationItem("Post " + Post.PostID.ToString, textContent, New Uri(baseURL + "/Post/View/" + Post.PostID.ToString), "Post" + Post.PostID.ToString, Post.Date) items.Add(Item) Next If items.Count = 0 Then ''//send a 304 to the browser. Return View("304") End If feed.Items = items feed.Language = "es-ar" feed.LastUpdatedTime = (From i In items Select i.LastUpdatedTime Order By LastUpdatedTime Descending).FirstOrDefault ''//Not needed in this sample. ''//Dim link As New SyndicationLink(New Uri("http://server/link"), "alternate", "Link Title", "text/html", 1000) ''//feed.Links.Add(link) ViewData("feed") = feed Return View("Rss") End Function </code></pre> <h2>Rss View (rss.aspx)</h2> <pre><code>Dim htmlwriter As System.IO.Stream = Response.OutputStream Dim rssWriter As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(htmlwriter) Dim feed As System.ServiceModel.Syndication.SyndicationFeed = ViewData("feed") Dim rssFormatter As New System.ServiceModel.Syndication.Rss20FeedFormatter(feed) rssFormatter.WriteTo(rssWriter) rssWriter.Close() </code></pre> <p>This way, you can reuse the view</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload