Scott on Writing

来源:百度文库 编辑:神马文学网 时间:2024/04/27 15:43:41
FeedBurner and Changing a Blog‘s Feed URL
This weekend I moved over my RSS feed - previouslyhttp://ScottOnWriting.NET/sowBlog/Rss.aspx - to a feed managed byFeedBurner (http://feeds.feedburner.com/ScottOnWriting).  FeedBurner serves as a sort of feed URL proxy.  Basically you give FeedBurner a link to your RSS feed and it creates a feed based on that feed.  You then point your subscribers to the FeedBurner feed and FeedBurner serves up your site‘s content, maintains statistics on who‘s subscribing to your blog, and so on.
I decided to move to FeedBurner to realize three benefits (keep in mind that ScottOnWriting.NET (still) runs off of an old version ofScott Watermasysk‘s.Text blogging engine, as I‘ve yet to upgrade toCommunity Server; previous to today, I was actually using a pre-0.94 version, but today "upgraded" to the official 0.94 release downloadable from the .Text GotDotNet Workspace):
Subscription statistics - FeedBurner provides a number of free statistics, including number of subscribers, number of requests, and aggregator breakdown. Someone else handles the bandwidth - currently requests to the RSS feed on ScottOnWriting.NET consume roughly 1.5 GB of traffic per week, or 6 GB of traffic per month (in total, ScottOnWriting does about 11 GB of traffic per month).  That‘s a lot of 1s and 0s that would be nice to offload to another party.  (I don‘t believe the pre-0.94 version of .Text I was using supportedconditional HTTP GETs (although if I‘m not mistaken the "official" 0.94 release does; had I been using a version that supported conditional GETs this bandwidth requirement would be an order of magnitude lower, I‘d wager, perhaps just a GB for the month.)  (To clarify, while FeedBurner does make requests to the blog‘s RSS URL, it caches the results for a period of time, thereby reducing the bandwidth demands for my server.) FeedBurner has a couple of neat “publicizing“ tools - FeedBurner includes a number of tools to easily make links to add your blog to My Yahoo!, MyMSN, newgator Online, and so on.  Additionally, there are nifty little tools you can use to “show off“ how many folks subscribe to your blog, a la:
When changing over your RSS feed URL the main challenge is making sure that your existing subscriber base starts to use the new feed URL.  There are, to my knowledge, to ways this can be done, with the first of the two ways being the ideal way:
Have your old feed URL emit an HTTP 301 status code - TheHTTP 301 status code is a message from the server to the client saying, “Hey, this resource has been permanently moved to URL xyz.“  The client, then, can make a new request to the specified URL; too, if there‘s some database being used to track the URL, this message informs the client that it‘s time to update the database and use the new location.  If I‘m not mistaken, virtually all modern aggregators support HTTP 301 status codes and will automatically update a site‘s feed URL to use the newly specified location. Tell people of your new feed URL - if you do not have control over your blog website you may not be able to take the steps needed to replace the current feed URL with an HTTP 301 status code.  In this case, the only approach I know of to inform users of the new feed URL is simply through word of mouth.  That is, you‘ll just have to post on your blog an entry telling users to update their aggregators.  AsKent Sharkey has noted, though,the results may be somewhat disappointing.
Since I run ScottOnWriting.NET myself (well, through a web hosting company), I have control over these matters.  The only challenge, then, was getting .Text to play nice.  In .Text version 0.94 the site‘s RSS feed comes from a file named Rss.aspx.  This file, though, does not actually exist; rather, in the Web.config file all requests are handed off to a .TextHTTP Handler.  When a request comes in for Rss.aspx, .Text generates the appropriate output.
To get Rss.aspx replaced with an HTTP 301 status code, the first step is to create an Rss.aspx file in your blog‘s root directory.  The code needed for this page is alarmingly simple - all you want to do is return an HTTP 301 specifying the new feed URL, like so:

(Of course replace thehttp://feeds.feedburner.com/ScottOnWriting Location header value with the URL of your new RSS feed...)
Creating this file is not enough.  In fact, even after creating this file if you visit Rss.aspx through your browser you‘ll still see the complete RSS feed rather than being auto-redirected to the specified URL.  This is because the ASP.NET engine is handing off the request to the .Text HTTP Handler rather than handling the request itself.  If you look at the section in the Web.config file you‘ll find an entry like:

This entry says, “Any request for an ASP.NET page should be handled by the class Dottext.Framework.UrlManager.UrlReWriteHandlerFactory,Dottext.Framework,” and HTTP Handler. This includes requests for Rss.aspx.  Hence we need to add the following line to the section:

That tells the ASP.NET engine to take care of requests to Rss.aspx.  At first I naively thought that I was done, but I had just unwittingly setup an infinite loop!  When a request comes into Rss.aspx, it sends back a 301 status code to the client, saying, “No, no, no, you want to go to this FeedBurner URL.“  This is what we want to tell people coming through a browser or aggregator, but remember that FeedBurner also needs to know the URL of the site‘s feed, which, at this point, I had set simply as Rss.aspx!  So when FeedBurner periodically checked to see if a new version of my feed was available it requested Rss.aspx, which told it to check itself, which says to check Rss.aspx, which says to check itself, which... you get the point.
Instead, what I needed to do was rename .Text‘s Rss.aspx to something else, like RssFromText.aspx and instruct FeedBurner to use this alternate, “secretive” feed URL.  With this setup, a user who already subscribes to ScottOnWriting.NET through Rss.aspx will automatically be switched over to FeedBurner.  FeedBurner‘s RSS content will be populated from RssFromText.aspx, which will be generated from .Text, reflecting the most recent blog entries.  No more infinite loops!
To accomplish this I had to edit blog.config to tell .Text that it should use RssFromText.aspx as its RSS feed URL as opposed to Rss.aspx.  This involved updating the appropriate  line like so:

With this addition, requests now to Rss.aspx are sent back an HTTP 301 status code, but FeedBurner can still slurp down the site‘s content through RssFromText.aspx.
Next, you‘ll probably want to update the link to the site‘s feed in the My Links section (since this will point the users to Rss.aspx, but you want them to go directly to the FeedBurner link).  (In actuality, this step is probably optional since even if you do leave it as Rss.aspx, when the attempt to view that page through a browser or slurp it through an aggregator, they‘ll get the 301 status code and auto-redirect to the FeedBurner URL... but still, for completeness let‘s change this link.)  To accomplish this, simply edit the MyLinks.ascx file in the ~/Skins/skin_name/Controls/ directory.  With version 0.94 you‘ll find two HyperLink controls that .Text automatically looks for and sets their NavigateUrl properties to Rss.aspx - these controls have IDs Syndication and XMLLink.  Even if you explicitly set the NavigateUrl properties to your FeedBurner URL, .Text will overwrite it and the link will be rendered as Rss.aspx.  If you try to simply remove these HyperLink controls you‘ll find that (at least with 0.94) .Text will barf.  What I did was simply set their Visible property to False.  I then added two HyperLink Web controls of my own that referenced the new feed URL.
There‘s one more facet that should be changed, although I‘ve not made the change since (to my understanding) you‘d need to actually hack the .Text source code, recompile, and re-deploy.  In the portion of the web pages in your blog you‘ll find a tag that‘s used for RSS feed auto-discovery:

Ideally the href attribute would contain the URL of your new feed... but I didn‘t feel like going through the headache of pecking through the source, making a change, testing, and so forth.  So I just left it as-is, figuring in the worst case someone will “discover” my feed to be Rss.aspx, which will automatically be updated to the FeedBurner syndication URL as soon as their aggregator makes its first request to Rss.aspx.
The FeedBurner service looks pretty cool upon first glance.  Once this new feed URL gets some use and I get some metrics in FeedBurner‘s database, I plan on sharing some of the stats... it‘ll be interesting to see what the most popular aggregator out there is for those who are ASP.NET developers (the primary audience of this blog, I imagine), among other data points.
posted on Sunday, August 28, 2005 5:23 PM
_xyz