Dave Burke : Freelance .NET Web Developer specializing in Online Communities

dotText fix for robots and browsers that add a slash to /RSS urls

Problem clients are the ones you like and who ask you about stuff you want to fix, whether you're billing them or not.  Loyalty, friendship, or me just being a putz, I don't know.  But this was an interesting dotText issue so I had to investigate.

Seems certain robots or browsers (I don't know the exact circumstances) were adding a slash to the end of a dotText categories RSS URLs.

http://myblog.com/category/1/rss became http://myblog.com/category/1/rss/ and generated a "Resource Cannot be Found" error.

ScottW had the final slash covered two years ago, I mean, there's a WebPathStripper class with a RemoveRssSlash(string url) method to make sure a correct URL is being generated!  What else can he be expected to do? 

What we needed was a simple way to detect the final slash and get rid of it.  Here's the fix.

The original RemoveRssSlash(string url) looks like this:

public static string RemoveRssSlash(string url)
{
 return Regex.Replace(url,"/rss$",string.Empty);
}

Change it to the following to detect the final slash:

public static string RemoveRssSlash(string url)
{
 if (url.EndsWith("/"))
  url = url.Substring(0,url.Length - 1);
 return Regex.Replace(url,"/rss$",string.Empty);
}

Okay, now we have to modify the HttpHandler pattern for categories in the web.config.  If you have supplemental category types (like "terms", "taxonomy", etc, those lines have to updated as well.)

Add a "/?" to the regex pattern, or change

<HttpHandler pattern = "^(?:\/(\w|\s|\.)+\/category\/(\d|\w|\s)+\.aspx/rss)$" type=...

to

<HttpHandler pattern = "^(?:\/(\w|\s|\.)+\/category\/(\d|\w|\s)+\.aspx/rss/?)$" type=...


This will cause all URLs ending in "/rss/" to be handled by the RssCategoryHandler class along with the properly structured "/rss" URLs.  Bake at 350-degrees in a pre-heated oven for 45 minutes and you have a delicious URL to be enjoyed by the entire HTTP consuming family!

 

Comments (2) | Post RSS RSS comment feed

Posted on 3/14/2005 10:10:00 PM by Dave Burke
Categories:
Tags:

Related posts

Comments (2) -

3/15/2005 11:19:00 PM Permalink

What file is this in? I can't find it...

vern |

3/16/2005 7:48:00 AM Permalink

Vern,  I'm sorry.  I didn't explicitly say, did I?  You'll find it in webPathStripper.cs class in the UTIL folder of the Dottext.Framework project.  btw, a good way in Visual Studio to root this stuff out is by using a global search with [ctr][shift]-F.  I use it ALL THE TIME when figuring out what's what in dottext.

Dave Burke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke