Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello everyone, i have this web project i have developed, i am retrieving rss feeds from twenty different websites on page load of the home page and insert them to SqlServer database, but it takes almost forever for the feeds to load and display. i have tried using output Caching so to optimize site performance, still could not display faster.

Please does anyone know what to do here? Below is my code:

//web.config file

XML
<caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="CacheHour" duration="100" varyByParam="none" location="Any"/>
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>


//.aspx file
C#
<%@ OutputCache CacheProfile="CacheHour" %>

private void loadFeedLindaIkeji()
   {
       try
       {
           //RssFeedClass rsscls = new RssFeedClass();

           WebRequest MyRssRequest = WebRequest.Create(@"C:\inetpub\wwwroot\RSSFEED\App_Data\XMLFile2.xml");
           //WebRequest MyRssRequest = WebRequest.Create("http://feeds.feedburner.com/blogspot/OqshX");
           WebResponse MyRssResponse = MyRssRequest.GetResponse();
           Stream MyRssStream = MyRssResponse.GetResponseStream();
           // Load previously created XML Document
           XmlDocument MyRssDocument = new XmlDocument();

           MyRssDocument.Load(MyRssStream);
           MyRssList = MyRssDocument.SelectNodes("rss/channel/item[position()<7]");


           string sTitle = "";
           string sUrlFriendlyTitle = "";
           string sLink = "";
           string sDescription = "";
           DateTime? sDate = null;
           string sAuthor = "Linda Ikeji";


           // Iterate/Loop through RSS Feed items
           for (int i = 0; i < MyRssList.Count; i++)
           {
               XmlNode MyRssDetail;

               MyRssDetail = MyRssList.Item(i).SelectSingleNode("title");
               if (MyRssDetail != null)
               {
                   sTitle = MyRssDetail.InnerText;
                   sUrlFriendlyTitle = rsscls.URLFriendly(sTitle);
               }
               else
                   sTitle = "";

               MyRssDetail = MyRssList.Item(i).SelectSingleNode("link");
               if (MyRssDetail != null)
                   sLink = MyRssDetail.InnerText;
               else
                   sLink = "";

               MyRssDetail = MyRssList.Item(i).SelectSingleNode("pubDate");
               if (MyRssDetail != null)
                   sDate = Convert.ToDateTime(MyRssDetail.InnerText);
               else
                   sDate = null;
               MyRssDetail = MyRssList.Item(i).SelectSingleNode("description");
               if (MyRssDetail != null)
               {
                   sDescription = MyRssDetail.InnerText;
               }
               else
               {
                   sDescription = "";
               }


               // Now generating HTML table rows and cells based on Title,Link & Description

               HtmlTableCell block = new HtmlTableCell();

               block.InnerHtml = "<span style="font-weight:bold;"><a href="1111.aspx?n=" + rsscls.URLFriendly(sTitle) + "">" + sTitle + "</a></span>";

               HtmlTableRow row = new HtmlTableRow();

               row.Cells.Add(block);
               tblFeedLindaIkeji.Rows.Add(row);

               HtmlTableCell block_description = new HtmlTableCell();

               block_description.InnerHtml = "<p align="justify" style="border-removedsolid 1px #000;">" + DateTime.Parse(sDate.ToString()).ToString("MMMM dd, yyyy") + "</p>";

               HtmlTableRow row2 = new HtmlTableRow();

               row2.Cells.Add(block_description);

               tblFeedLindaIkeji.Rows.Add(row2);

           }
       }
       catch (Exception)
       {
           HtmlTableCell block = new HtmlTableCell();

           block.InnerHtml = "<h4>Linda Ikeji Feeds Temporarily Unavailable!<h4 />";

           HtmlTableRow row = new HtmlTableRow();

           row.Cells.Add(block);
           tblFeedLindaIkeji.Rows.Add(row);
       }
   }
Posted
Updated 4-Feb-14 22:19pm
v3
Comments
Maarten Kools 5-Feb-14 3:48am    
Why not load the RSS feeds client side using AJAX? The feeds will still have to be loaded, but the user experience will be so much better.
Uwakpeter 5-Feb-14 4:07am    
how do i use Ajax for this?
Maarten Kools 5-Feb-14 4:40am    
Ahmed Bensaid 5-Feb-14 3:58am    
Are you using a stored procedure ?
Uwakpeter 5-Feb-14 4:09am    
yes i am using stored procedure for the insertion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900