This project is read-only.

Link Date Format

Feb 12, 2010 at 12:59 AM

I just installed Elmah to log any errors that occured on our blog.  This enabled us to find out that some links were broken to our site.  For example the link:!.aspx

is broken, but this link is not:!.aspx

This is a big problem because external sites are linking to our posts and are getting error pages.

What can I do to change this?  Could not find anything on google.


Feb 12, 2010 at 2:45 AM

Where is the top link coming from, or where is it being output on your site?

BE has two format options -- (1) with the date in the URL, and (2) without the date in the URL.

With the Date option, the date is going to be year/month/day -- e.g. 2008/02/11.  There's nothing in BE I can think of that would output a link for a post that only has the Year/Month without the day.

If you can find where that bad link is being output on your site, we can solve that.  But otherwise, it's not your responsibility to account for every invalid link someone may be arbitrarily typing in their address bar or publishing somewhere for others to click on and end up getting 404s.

Feb 12, 2010 at 1:46 PM

Hi Ben

All our pages indexed by google and links from other sites are using the year/month pattern!

For example this page has a link to our blog:

I really need some help here.

Feb 12, 2010 at 2:40 PM

I searched the code and found a change made by BenAmanda in svn revision 29143 in the class BlogEngine.Core.Web.HttpModules.UrlRewrite in the function RewritePost.  The condition to find a post was modified from:

Post post = Post.Posts.Find(delegate(Post p)
if (date != DateTime.MinValue && (p.DateCreated.Year != date.Year || p.DateCreated.Month != date.Month))
if (p.DateCreated.Day != 1 && p.DateCreated.Day != date.Day)
return false;

return slug.Equals(Utils.RemoveIllegalCharacters(p.Slug), StringComparison.OrdinalIgnoreCase);



Post post = Post.Posts.Find(delegate(Post p)
if (date != DateTime.MinValue &&
(p.DateCreated.Year != date.Year || p.DateCreated.Month != date.Month || p.DateCreated.Day != date.Day))
return false;
return slug.Equals(Utils.RemoveIllegalCharacters(p.Slug), StringComparison.OrdinalIgnoreCase);


This had for effect that this link was valid before:!.aspx

But now it isn't with this new code anymore.  This broke a lot of links other site were linking to us.

I found out also that in svn revision 8906 madkristensen modified the property RelativeLink from:

return Utils.RelativeWebRoot + "post/" + DateCreated.Year + "/" + DateCreated.ToString("MM", CultureInfo.InvariantCulture) + "/" + slug;


return Utils.RelativeWebRoot + "post/" + DateCreated.ToString("yyyy/MM/dd/", CultureInfo.InvariantCulture) + slug;

But since our blog has been running for 3 years, our old post were using the yyyy/mm pattern before and other sites were linking to those URL.

I did a custom modification (ignore the day in the find post) to the code and redeployed our blog and it fixes my problem.  But it seems like a big problem for people who have run for a long time and have accumulated links from other sites in the past. 

I am pretty happy that Elmah reported those problem because otherwise I would never have found out.



Feb 12, 2010 at 8:04 PM

This was introduced while fixing this bug.

Feb 12, 2010 at 10:13 PM

Thanks, good investigative work.  It sounds like a long time ago, URLs for posts had just the Year/Month without the day, or this was at least an optional format.

I don't *think* there's any URLs that are published with just Year/Month in BE 1.6, BE 1.5 and even BE 1.4.5.

But yes, I can see how for people who have been running BE for a while and their links are out there with just the Year/Month format, this is a problem.

On your blog now, there's no links being output with just Year/Month format, right?

I think that code in RewritePost can be modified so it handles the Year/Month format, while still addressing the problem in Issue # 9212.  I'll come up with a version that does so.

At least you have it fixed right now on your blog -- that's good.

Feb 12, 2010 at 11:25 PM

I just checked in a fix for this -- version

The code can be seen here.  Both Year/Month and Year/Month/Day formats are now handled.  Best of both worlds!

Thanks for identifying this.