Joshua Stengel

Everything...Is going...
To be okay!

UserAgent Fix for the RSSToolkit 2.0.0.0

I frequently use the RSSToolkit to consume and display RSS feeds from other blogs.  Recently, I've noticed problems with the RSSToolkit not being able to display feed from some external sources.  In particular, I've been having trouble consuming feeds from external blogs like Blogspot and Feedburner.  The symptoms appeared over the past month or two and included the disappearance of consumed blogs and new blog posts.

After some digging, I found this entry on Obishan's blog that gave me a clue. Using Web-Sniffer, I was able to verify that if no UserAgent was provided for the request, the request was redirected (302).  This redirection seems to the source of my problems with the RSSToolkit and I'm not the only one.

This wasn't my first crack at fixing an issue with the RSSToolkit, so I spent some time tracking done how to fix this issue. Basically, I needed to find out where the RSSToolkit was actually requesting the RSS and find out how to modify the request so that it included a UserAgent. In my fix I am hardcoding in the UserAgent.  Ideally, this would be set through a property in the control.

The Fix

Step 1: Download the Source

Step 2: Update the Code

Open RSSToolkit > RSS > DownloadManager.cs and replace the DownloadFeedDom() with the following:

private CacheInfo DownLoadFeedDom(string url)
        {
            //// look for disk cache first
            CacheInfo dom = TryLoadFromDisk(url);

            if (CacheReadable(dom))
            {
                return dom;
            }

            string ttlString = null;

            //MODIFICATION: Some RSS sources like Facebook and Feedburner look
            //for a UserAgent (browser/OS information)

            String userAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
            HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
            httpRequest.UserAgent = userAgent;
            HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            XmlDocument doc = new XmlDocument();
            doc.Load(httpResponse.GetResponseStream());
            httpResponse.Close();
            doc.Save(Console.Out);

            //END OF MODIFICATION

            if (doc.SelectSingleNode("/rss/channel/ttl") != null)
            {
                ttlString = doc.SelectSingleNode("/rss/channel/ttl").Value;
            }

            //// compute expiry
            int ttlMinutes = GetTtlFromString(ttlString, _defaultTtlMinutes);
            DateTime utcExpiry = DateTime.UtcNow.AddMinutes(ttlMinutes);

            //// save to disk
            return TrySaveToDisk(doc, url, utcExpiry);
        }

Step 3: Rebuild the Project and use the new RssToolkit.dll

(Optional) Step 4: Download my copies.  My versions also include my fix for Atom feeds.

Comments

alexdresko said:

Man, this stuff needs to get in the current release!!!!!!

# July 25, 2008 2:35 PM

Jake said:

BRILLIANT.

legend.

# July 29, 2008 3:45 PM

Ben Strackany said:

Awesome ... I was pulling my hair out trying to figure out why Feedburner was returning old posts when I used RssToolkit but not with anything else. Now it works!

The other nice thing is your replacement code allows us to set an HTTP timeout in case the remote server is down.

# August 19, 2008 5:00 PM

finalevil said:

Thanks for your post. I just have encountered this problem.

# September 24, 2008 10:37 AM

Steve Trefethen said:

Cool, thanks for posting the code!

# November 7, 2008 7:07 PM

Kenneth Andersson said:

Finally a solution to this "mystery".

Thanks a lot!

# November 20, 2008 10:34 AM

SelArom said:

good god why is this not in the current release?! I almost lost a nut trying to figure out why feedburner was giving me 404 errors...

thanks!

# December 22, 2008 6:43 PM

Feedburner torched my feeds » orangeSplotch.com said:

Pingback from  Feedburner torched my feeds » orangeSplotch.com

# February 13, 2009 12:50 PM

Kindra Bible said:

I took your .dll file from above and put it into my site.  But, I am still getting "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond " when connecting to feedburner. Any ideas?

# December 6, 2009 2:13 PM

jstengel said:

I noticed there seemed to be another change recently with feedburner.  I had one client who lost connection (like you) and another where the feed started linking to post comments.  It was strange.  I think I switched them to the atom feed instead of the RSS (or vice versa) and that seem to fix it.  That's not a good fix, but that's all I've got for now. :-)

# December 6, 2009 5:51 PM

skateboard cupcakes said:

"Have you ever regarded as including much more movies on your website posts to hold the readers a lot more entertained? I mean I just go through as a result of the total article of yours  and it was quite very good but considering that I am far more of a visual learner,I located that to become much more useful. Just my my thought, Great luck   "

--------------------------------------------

my website is <a href="zeroskateboards.org/.../cool-skateboards-images-10.html">cool skateboarding</a> .Also welcome you!

# December 4, 2010 4:03 AM

Learn to Speak French said:

"As a Newbie, I am always browsing on the net for content which will support me. Thank you"

--------------------------------------------

my website is  

harleydavidsonmotorcyclesblog.com

Also welcome you!

# December 6, 2010 12:50 PM

ipad accessories said:

-----------------------------------------------------------

"you know, i used to be just thinking of how poor people today are receiving when they're attempting to market a site, i mean, for instance, look at this location, nothing but  spam. appears so desperate, why not only do adverts instead of spamming all the time."

# January 8, 2011 7:49 AM

Marilyn Oliver said:

Hey, cool web site. I seriously came upon this on Bing, and i'm stoked I did. I'm likely to definately be revisiting ideal right here an excellent deal much more often. Wish I could add on the write-up and bring just a little considerably far extra for the table, but I'am just absorbing as substantially information as I can inside the second.

# July 1, 2011 2:07 AM

Kacie Teabo said:

I don't even understand how I stopped up right here, having said that I thought this put up was wonderful. I do not recognize who you might be but surely you are going to a well-known blogger inside the event you are not already. Cheers!

# July 5, 2011 6:15 AM

ball gowns said:

This is a great post; it was very informative. I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it.

# July 11, 2011 7:49 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)