BlogEngine.NET 2.5 Upgrade

by Alex Meyer-Gleaves 31 July 2011 - 6:39 AM

I just upgraded to BlogEngine.NET 2.5 and found the process to be fairly straight forward. The upgrade instructions suggest that you start from a v2.5 installation, and then copy your existing data and settings into the fresh install. I did this and then copied some additional files that were not explicitly mentioned in the instructions. Most of these were files that I added myself to customise the blog.

  • The apple-touch-icon.png file into the root folder.
  • Extensions I added into the App_Code/Extensions folder.
  • The assembly for a custom extension I wrote into the bin folder.
  • SQL Server CE runtime files and .NET provider assembly into the bin folder.
  • JavaScript files for the jQuery lightBox plugin that I use.

After the upgrade I did get one compiler error in the SimpleDownloadCounter extension.

Compiler Error Message: CS1061: 'BlogEngine.Core.BlogSettings' does not contain a definition for 'StorageLocation' and no extension method 'StorageLocation' accepting a first argument of type 'BlogEngine.Core.BlogSettings' could be found (are you missing a using directive or an assembly reference?)

That was easily fixed by replacing the occurrence of BlogSettings.Instance.StorageLocation with BlogConfig.StorageLocation.

I moved from VistaDB to SQL Server CE during the 2.0 upgrade so that more difficult migration was already done. This time I only needed to run the SQL_CE_UpgradeFrom2.0to2.5.sql upgrade script to update my SQL Server CE database schema. I used the SQL Server Compact Toolbox add-in for Visual Studio 2010 to run the script and had no problems.

Because I run a custom theme I check for new additions to the Standard theme and add any that I feel are required into my own. A quick check of the differences showed a new item was added to the header menu in the site.master file. It adds a link to the menu that allows a user to switch between the regular and mobile version of the site when viewed on a mobile device.

<% if (Utils.IsMobile)
   { %>
<li><blog:MobileThemeSwitch runat="server" /></li>
<%
   }
%>

It seemed like a cool feature so I added the new code to my custom theme and tested the site from my iPhone to check that the new menu item was working. There were also a couple of CSS modifications that I moved over too. The last thing was to fix the titles on the Recent Comments and Recent Posts widgets. Either the space in the titles was removed during the upgrade or they were never there and I have only just noticed.

Overall, nothing too stressful. The complete list of new features in 2.5 can be found here.

Tags:

BlogEngine.NET

Switching to reCAPTCHA for Comment Spam protection

by Alex Meyer-Gleaves 30 March 2010 - 1:45 AM

reCAPTCHA I recently posted about using CAPTCHA on my blog in an attempt to reduce the amount of comment spam. The implementation I posted about has worked well for me but I decided I would like to switch to reCAPTCHA. Not only is this free CAPTCHA service robust and well tested, it also helps to digitize books, newspapers and old time radio shows. Taking the thousands of hours people spend entering CAPTCHA information each day and utilizing them for an additional purpose is a brilliant idea.

As with the previous solution I was sure that someone would have already done the work to integrate reCAPTCHA with BlogEngine.NET. My assumption was correct and I quickly found a solution in the form of an extension written by Filip Stanek. I followed the simple installation process and had the control appearing in the comment form straight away. After a short period of testing I quickly found a couple of problems. Once the first comment was added all subsequent comments entered resulting in an error that was reported via the callback. The log viewer added to the administration area was also throwing an exception and failing to load.

I tracked both of these problems down to the extension expecting the return value from BlogService.LoadFromDataStore to be a Stream. This method returns an object instance and delegates its work to the currently configured BlogProvider. The BlogProvider.LoadFromDataStore method also returns object, and it turns out that the type of the object returned will be different depending on the provider being used. My data store is a VistaDB.NET database so I am using the DbBlogProvider instead of the default XmlBlogProvider. Unfortunately the DbBlogProvider returns a string and the XmlBlogProvider returns a Stream. There is nothing stopping the next provider that is written from returning yet another type. This no doubt makes life difficult for those writing BlogEngine.NET extensions.

To get the extension working with the DbBlogProvider you will need to make a couple of small changes. In the Recaptcha.cs file, find the code below in the UpdateLog method.

Stream s = (Stream)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (s != null)
{
    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
    log = (List<RecaptchaLogItem>)serializer.Deserialize(s);
    s.Close();
}
log.Add(logItem);

Replace it with the following code.

string data = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (!string.IsNullOrEmpty(data))
{
    using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(data)))
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
        log = (List<RecaptchaLogItem>)serializer.Deserialize(stream);
    }
}
log.Add(logItem);

In the RecaptchaLogViewer.aspx.cs file, find the code below in the BindGrid method.

Stream s = (Stream)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (s != null)
{
    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
    log = (List<RecaptchaLogItem>)serializer.Deserialize(s);
    s.Close();
}

Replace it with the following code.

string data = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (!string.IsNullOrEmpty(data))
{
    using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(data)))
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
        log = (List<RecaptchaLogItem>)serializer.Deserialize(stream);
    }
}

You should now be able to use the extension with the DbBlogProvider without any problems. The rest of the extension seems to work without any problems and appears to be well written overall. It is definitely worth checking out if you are looking for a reCAPTCHA solution for BlogEngine.NET.

Tags:

BlogEngine.NET | Web Development

Comment Spam protection for BlogEngine.NET

by Alex Meyer-Gleaves 25 February 2010 - 12:38 AM

image The amount of comment spam I have been getting on this blog has increased significantly in recent months, and I decided it was finally time to do something about it. I have been using an Akismet comment filtering extension for a long time now but the flow of comment spam continued to rise. There is now an Akismet extension included in BlogEngine.NET 1.6 and I will continue to use it because the more layers of protection the better.

I wanted to complement the Akismet extension with a CAPTCHA based solution and figured that the problem would no doubt have already been tackled by someone else. This was certainly the case, and after settling on this solution outlined by Michael Ceranski, I had the implementation deployed and working in a couple of minutes. The only hesitation I had with the solution is that it requires changes to the BlogEngine.NET code, and I will have to remember to merge them into newer versions when I upgrade. I usually have a number of changes to merge during an upgrade anyway, and if the end result is less spam then it will be well worth it. Now to wait and see how well this CAPTCHA based solution works.

Tags:

BlogEngine.NET

Content missing from FeedBurner feed

by Alex Meyer-Gleaves 18 March 2009 - 8:43 PM

RSS Feed Logo After moving my FeedBurner account over to Google I found that content was no longer appearing in my feed. I tried pinging and resyncing my feed but it made no difference. My feed was being formatted as ATOM 1.0 by BlogEngine.NET so I changed it to RSS 2.0 to see if that would help. For some reason after performing another resync the content was now appearing. This seemed strange as I never had a problem prior to my account being moved Google.

To confirm that it wasn’t just a fluke I changed the format back to ATOM 1.0, and sure enough the problem appeared again. Switching back to RSS 2.0 once again fixed the problem. I have used the W3C Feed Validation Service to confirm that my feed is valid, so the problem is clearly not the source feed, but rather a problem that has surfaced after moving my account.

Having sorted the first problem out, there were now duplicate posts appearing in Google Reader for my feed. Once I switched my feed format to RSS 2.0 and regained the missing content Google Reader assumed I had new posts and added them to its cache. When feeds are cached by Google Reader feed items are never removed and only updates are noted in the cache. I assume this is because it's impossible to tell the difference between a post that was actually deleted and one that is simply no longer included in the feed.

I’m not aware of a way to clear the cache for a feed in Google Reader, so I switched to an alternative base address for my FeedBurner feed that hadn't already been cached. My FeedBurner account indicates that the base address for my feed is feeds2.feedburner.com. I switched to using feedproxy.google.com as the base address instead and the duplicates are now gone. I hope Google manages to sort out the problems people are having as it would be a shame to see them loose FeedBurner accounts.

Tags:

BlogEngine.NET

SyntaxHighlighter 2.0

by Alex Meyer-Gleaves 20 February 2009 - 1:56 AM

I was pleased to find out that a new version of SyntaxHighlighter has been released. New features including smart line wrapping, 100% standards compliance, additional themes and hosted versions of the source files. The documentation on the new wiki is also very good. It is obvious that Alex Gorbatchev has put a lot of effort into this release and should be commended. Below is a little “hello world” sample highlighted using the new version:

using System;

namespace HelloWorld
{
    /// <summary>
    /// A "Hello World!" program in C#.
    /// </summary>
    class Hello 
    {
        /// <summary>
        /// The main entry point.
        /// </summary>
        static void Main() 
        {
            System.Console.WriteLine("Hello World!");
        }
    }
}

Tags:

BlogEngine.NET | Web Development

jQuery lightBox with BlogEngine.NET and WLW

by Alex Meyer-Gleaves 14 February 2009 - 8:48 PM

It’s always a good idea to separate content from behaviour, and this is the reason I don’t like the idea of adding rel attributes to my anchor tags in order to support Lightbox. I may decide one day that I want to use Highslide or another library instead, and I certainly don’t want to massage the HTML of my existing posts or put in hacks to support the new library.

When adding an image to a post using Windows Live Writer the resulting HTML looks similar to that below. An image tag that displays the thumbnail image is nested inside an anchor tag that links to the full size image.

<a href="foo.jpg">
    <img title="Foo" alt="Foo" src="foo_thumb.jpg">
</a> 

If you provide an alternate description for the image in WLW, it is as you would expect, applied only to the image tag. Many of the variations of the Lightbox library get the description to display in the Lightbox from a title attribute on the anchor tag. This is a problem that jQuery and jQuery lightBox can solve for us without our needing to touch the HTML generated by WLW.

jQuery lightBox is a jQuery implementation of Lightbox. It enables you to add the Lightbox effect to any image, or more specifically anchor tag, that you can select with a jQuery selector. The power of jQuery selectors can do the heavy lifting to find the images, so there is no need to add attributes to the HTML content that serve only as identifiers for the Lightbox script.

Download jQuery lightBox and upload it to your BlogEngine.NET website. Add the markup below to the head tag in the site.master file for your theme. Make sure you update the folder names to match your upload location and the file names to match the version you downloaded. You may also need to update the image paths in the jQuery lightBox script (jquery.lightbox-0.5.js). If you already have a reference to the jQuery library you do not need to add the one included with the plugin (jquery.js). I am currently using the plugin with jQuery v1.3.1 without any problems.

<link rel="stylesheet" href="/Extensions/Lightbox/css/jquery.lightbox-0.5.css" type="text/css" media="screen" />

<script src="/js.axd?path=Extensions/Lightbox/js/jquery.js" type="text/javascript"></script>
<script src="/js.axd?path=Extensions/Lightbox/js/jquery.lightbox-0.5.js" type="text/javascript"></script>

<script type="text/javascript" >
    (function($) {
        $(function() {
            $('div.text:has(a):has(img)').each(function() {
                $(this).find('a:has(img)').each(function() {
                    this.title = $(this).children('img').get(0).title;
                }).lightBox();
            });
    })(jQuery.noConflict());
</script> 

The strange anonymous function in the JavaScript code is to prevent a naming conflict between jQuery and BlogEngine.NET, as well as other JavaScript libraries such as Prototype that use $ as a function name.

The script identifies all the div tags with a class of text, that contain anchor tags, that in turn contain image tags. This restricts the Lightbox effect to images in post content and provides a way to create a Lightbox grouping for all images in the same post. Images that are in a group can be viewed inside the same Lightbox using next and previous buttons. The script also copies the title attribute from the nested image tag to the parent anchor tag. This ensures that descriptions you add for the image in WLW are presented in the Lightbox.

With only a little bit of effort we can keep our HTML clean and get the cool Lightbox effect as well. Below are some sample images you can test out to get a feel for the effect. You will notice that each image has a description and that you can navigate through them as a group.

 Road at night with bulb shutter-speed.

 View over the mountain tops.

Seashore that needs some sand.

Tags: , ,

BlogEngine.NET | Web Development

We Have Ignition!

by Alex Meyer-Gleaves 18 December 2008 - 4:52 PM

It's taken longer than it should but I've finally got around to setting up a blog for myself. Because I find it simple and extensible, I decided to run the blog using the ASP.NET based BlogEngine.NET. The project is run by Mads Kristensen, and he and the team are very active in bringing new features to BlogEngine.NET.

My theme is based mostly on the Standard theme that comes with BlogEngine.NET, along with some nice touches from the Business theme that was created for DasBlog by Christoph De Baene. Keeping my theme close to the Standard theme should make it much easier for me to merge in new theme related changes. I can always find the differences between versions of the Standard theme and merge them into my own.

I'm using the VistaDB Express data provider for storing my blog data as I don't want to pay the premium for a SQL Server database, and I would prefer to keep my data in a relational database rather than in XML files.

Hopefully this is the first post of many more to come.

Tags:

BlogEngine.NET

About the author

Alex Meyer-Gleaves I'm a Technical Architect living in Australia (that island like continent in the southern hemisphere). I love Microsoft .NET and C#. I hate early mornings, slow drivers and Lotus Notes.

Google Shared

 

Month List

Recent Posts

Recent Comments

Comment RSS

Links

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010