• Blog
  • Archive
  • About
  • Contact
Sign in

Welcome to rickardnilsson.net

rickardnilsson.net is a weblog and the online home of web developer and father of three, Rickard Nilsson... More

Rickard blogs about creating software solutions using ASP.NET and agile practices.

Sites I've visited recently

  • Twitter
  • Facebook
  • Philip Wildenstam
  • Ninetech - Affärsnytta med IT
  • JetBrains ReSharper
  • Vimeo
  • dnrTV!
  • YUI Theater
  • BlogEngine.Net

Categories

  • .NET
  • Agile
  • ASP.NET 2.0
  • ASP.NET 3.5
  • ASP.NET MVC
  • BlogEngine.NET
  • C# 2.0
  • C# 3.0
  • CSS
  • Design by Contract
  • Design Patterns
  • JavaScript
  • TDD
  • Unit testing
  • User tip

Five most recent posts

  • Dependency injection in ASP.NET MVC with Unity IoC Container
  • ReSharper templates from the Code Kata Cast
  • How to unit test code which depends on HttpContext.Current.Server
  • Code Kata Cast
  • TDD Masterclass in the UK with Roy Osherove

Tag cloud

  • agile
  • ajax
  • asp.net 3.5
  • blog
  • blogengine.net
  • c#
  • code kata
  • css
  • dbc
  • dependency injection
  • design by contract
  • dom
  • douglas crockford
  • fakes
  • foto
  • getweekofyear
  • gregoriancalendar
  • highlight
  • html
  • httpcontext
  • humble dialog box
  • inversion of control
  • ioc container
  • iso 8601
  • javascript
  • jquery
  • jscript
  • julian bucknall
  • live template
  • metaweblog api
  • model-view-presenter
  • mvp
  • patterns & practices
  • photo album
  • picasa
  • recent posts
  • refactor
  • refactoring
  • release
  • resharper
  • rhino mocks
  • roy osherove
  • syntax
  • syntax highlighter
  • tdd
  • tdd masterclass
  • test coverage
  • testing
  • types
  • unit test
  • unity
  • web service
  • week
  • widget
  • word 2007
  • yahoo
  • yui

Recent comments

  • Code Kata Cast (8)
    Rickard wrote: @Marcus Eklund Classical music is royalty free sin… [More]
  • Code Kata Cast (8)
    Marcus Eklund wrote: http://creativecommons.org/ is a good place. Cl… [More]
  • Code Kata Cast (8)
    Rickard wrote: @Johan Lindfors Thanks! @Andrea I use TestDrive… [More]
  • Code Kata Cast (8)
    Marcus Eklund wrote: Nice one Rickard, A bit quiet though :P Used to t… [More]
  • Code Kata Cast (8)
    Andrea wrote: Nice one You can use the R# test runner and assig… [More]
<< The Humble dialog v.2 | Blogging with MS Word 2007 >>

Problem with Related Posts in BlogEngine.NET 1.4

Sunday, 27 July 2008 03:35 by Rickard

With the new release of BlogEngine.NET a new feature was added that shows the description or part of the post when listing related posts. If the description is empty a small part of the post content is listed instead and here in lies the problem. The post content is simply clipped as a certain length without regard to any tags in the post. Let's say a related posts goes like this:

With the new release of
<a href="http://www.dotnetblogengine.net">BlogEngine.NET</a> a new feature was added.

Now, when the post is clipped it may end up cutting in the middle of the href:

With the new release of <a href="http://www.dotnetblo...

And this may probably screw up the layout and content of the remainder of the page, besides producing an html that will not validate.

Solution

This issue has been discovered and fixed for a future release of BlogEngine.NET. However, if you, like me don't or can't wait that long here's a fix:

The problem is that the html tags are not closed so the simple solution is to strip the related post of all html. My first thought was to parse the post and close all open tags but when I thought about the actual intent of the related posts I realized that it is to provide a preview of the post content, not to show part of the actual post. So, by stripping all html tags all images and links are removed and only the text remains, which provides a really nice preview.

To implement the solution you only have to edit one line of code in the App_Code/Controls/RelatedPosts.cs file on row 139:

string content = post.Content;

 

string content = Utils.StripHtml(post.Content);

Or you can download the appended file and replace the one in the App_Code/Controls/ folder.


RelatedPosts.cs (3,77 kb)

 

Tags:   blogengine.net, recent posts
Categories:   BlogEngine.NET
Actions:  
Share | |

Related posts

Building a Photo Album widget for BlogEngine.NETTutorial on how to implement the first steps of a Photo Album Widget for BlogEngine.NETSyntax highlighting in BlogEngine.NETBlogEngine.NET ships with an extension that automatically highlights source code in blog posts. All ...Ny blog med BlogEngine.NET Hej! Kul att du tittar in. Jag har äntligen haft möjlighet att flytta min gamla blog fr&...
 
Copyright © 2008-2009 rickardnilsson.net