The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Permanent Redirects via Code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Scott Watermasysk

Posts: 661
Nickname: scottwater
Registered: Aug, 2003

Scott Watermasysk is an ASP.NET developers. He wrote the .Text blog engine.
Permanent Redirects via Code Posted: Apr 14, 2004 6:12 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Scott Watermasysk.
Original Post: Permanent Redirects via Code
Feed Title: ScottW's ASP.NET WebLog
Feed URL: /error.aspx?aspxerrorpath=/blog/rss.aspx
Feed Description: ASP.NET and Blogging
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Scott Watermasysk
Latest Posts From ScottW's ASP.NET WebLog

Advertisement

At the the MVP Summit Scott Mitchell asked me what is the preferred way to redirect readers from one RSS feed to another.

My initial response was IIS can do this for you. You just tell IIS which file/directory/site you want to redirect and the new Uri. Many aggregators (RSSBandit, SharpReader, Newsgator, and FeedDemon) are smart enough to detect the permanent redirect (status code 301) and update their subscriptions accordingly.

However, if you do not have IIS access, you are not left out. Using my favorite new tool, “Fiddler”, I was able to quickly see a permanent redirect required just two steps:

  1. Setting the status code to 301
  2. Adding a location header for the redirect.

So now, it is just a matter of writing a couple lines of code:

string newUri = "http://scottwater.com/blog";
Context.Response.AddHeader("Location",newUri );
Context.Response.StatusCode = 301;
Response.End();

From here all you would need to do is drop this code in the “old” page, a custom httpModule, or even the global.asax. Obviously you could also add some logic to redirect pages to different locations, find pages with specific patterns, etc.

Speaking of redirects, a quick note to Aggregator authors. While it is very handy to have these updates occur without any user interaction, I would love to not have the redirect “save” until the new Url is validated (ie, you are sure it contains an RSS or Atom feed.). I know quite a few people who lost all of their subscriptions in the hotel's at the MVP summit because the once a day hotel internet registration got updated as the Url for every feed :)

Read: Permanent Redirects via Code

Topic: Pragmatic Unit Testing in C# with NUnit Previous Topic   Next Topic Topic: Imagine Cup - East Regional

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use