Running BlogEngine.NET on .NET 3.5

Sunday, 20 December 2009 12:41 by Haemoglobin

Unfortunately BlogEngine.NET is currently stuck back on .NET 2.0 due to a few lingering web hosts still not supporting .NET 3.5 yet.
Here is a comment made from Ben Amada, a BlogEngine.NET developer:

I agree, we can gain from using the new features in .NET 3.5.  You may or may not be aware that the BE core project has already been upgraded to .NET 3.5.  Some of the new .NET 3.5 compiler level features are being used -- but new namespaces such as Linq (and probably the Syndication namespace too) are not yet being used.  The website project is still on .NET 2.0.  Probably sooner than later, the website project too will be upgraded to .NET 3.5.

I think the main reason it hasn't yet been upgraded is because there are some BE users hosting their sites at webhosts that don't yet offer .NET 3.5.  The core project is at .NET 3.5, but because none of the new 3.5 namespaces are being used, the compiled core DLL can still be used in a .NET 2.0 environment.  At this point, I think just automatic properties and lambdas are being used in the core project (compiler level features).

Hopefully as the number of webhosts not offering 3.5 gets fewer and fewer, the website project too can be upgraded to .NET 3.5.

~~ BenAmada

 

If you want to write a user control or widget however in .NET 3.5 now for your BlogEngine.NET site (which I have needed to do) – it is relatively simple to do. All you need to do is modify the web project’s web.config slightly, you can see the changes that you need to make here:

The above diff was created using the report export functionality of WinMerge. p.s I wouldn’t normally recommend posting your web.config files to the web but in this case there are no “secrets” there.

General Tip:
In terms of making substantial modifications to your BlogEngine.NET instance (if you are in the habit of doing this, not necessarily just for this web.config change) – I recommend being connected to the BlogEngine.NET subversion repository (https://blogengine.svn.codeplex.com/svn) using TortoiseSVN. Now you can track any modifications that you make as Tortoise will flag the file as modified. Subversion will also attempt to automatically merge any further changes to the file that come from the BlogEngine.NET developers when you do an update, you of course won’t be able to submit your changes back unless you are part of their team. After doing the SVN update you can also monitor the changed files that come across and subsequently upload them to your web instance. Depending on if you are a risk taker or not, you may only want to do this when they mark a particular revision for a stable build.

Categories:   BlogEngine.NET
Actions:   E-mail | Permalink | Comments

Enabling Disqus Comments in BlogEngine.NET

Saturday, 28 November 2009 16:29 by Haemoglobin

Recently, I have switched across to using Disqus as the comments system on my blog instead of the inbuilt BlogEngine.NET comments.

Immediate benefits are:

  1. Threaded conversation (i.e you can reply to someone’s comment directly).
  2. Identify yourself with your Facebook or Twitter account (by logging in safely directly to the Facebook and Twitter sites respectively).
  3. If you subscribe to the comments conversation by email – you can use email to leave replies to comments on the website.
  4. Lets you keep track of comments you make across the blogosphere on all sites that use Disqus.
  5. As the owner of the site you can moderate directly from email notifications (i.e by replying with “Delete”). This makes moderation easy when out on the road.
  6. Generally looks sleek + many other reasons for using it (link#1, link#2, link#3).

I love comments so feel free to leave any and try the new system out!


Now, for the benefit of anyone using BlogEngine.NET who wishes to do this also, continue reading and I’ll outline the steps I took to do it:

  1. Create an account at http://disqus.com
  2. For Facebook integration, get your Facebook connect API key from http://developers.facebook.com/setup.php (you will also be asked to upload a xd_receiver.htm file to the root of your website).
  3. If you wish to use Akismet spam protection, use your Wordpress account API key located here http://dashboard.wordpress.com/wp-admin/profile.php (in small text at the top of the page)
  4. Within Disqus, under Settings –> General –> “Cross-domain Receiver URL” it describes an advantage to upload a blank.htm file to the root of your website and pointing to it.
  5. Under Settings –> Customize, change from the new Narcissus theme to either of the Classic ones. I found that the new Narcissus theme’s Reply and Edit buttons on a comment did not work for me as they initiate a post back and the AJAX action is lost. After some FireBug debugging I found that this simply because the buttons do not contain a “return false;” on their onclick events (works fine when I manually add this in using FireBug). I have sent an email to Disqus about this but as of yet have received no reply. [Update: It seems the Narcissus theme has been updated and it works fine now, and looks sleek – I would recommend this one now].

I made the following alterations to various files in my BlogEngine instance (note that some alterations are made to core BE.NET files themselves which is going to make upgrading BE.NET more of a pain but I believed it would be easy enough to integrate again if it was documented well enough, i.e here):

  1. Retrieve the second code snippet from http://disqus.com/comments/universal and add it to the “Tracking script” section of the BE.NET settings tab.
  2. Modify /theme/MyTheme/PostView.ascx, removing any html referencing the BE.NET comment system and replacing it with:
    <a rel="nofollow" href="<%=Post.PermaLink %>#disqus_thread">Comments</a>
  3. In the main /post.aspx change the visible property of the CommentView control to false:
    <uc:CommentView ID="CommentView1" runat="server" visible="false"/>
    And add the following: Yours will vary slightly, your version can be retrieved from the first snippet at http://disqus.com/comments/universal. Note the commented out disqus_developer variable, this can be uncommented to test the system on your local machine before deploying.
  4. Find the comments variable in /widgets/RecentPosts/widget.ascx.cs and replace the line with: While I was there, I also added a "Read more..." link that links to the archives page (which I think should be there): I do not use the RecentComments widget hence did not have to modify this - it would need to be however if it was used.
  5. Inside /archive.aspx.cs locate the comments.InnerHtml variable of the CreateTableRow method and replace it with: Note even though you can change what Disqus replaces the text with here by going to the Settings->Customize->Appearance Tab on your Disqus account, this is a global action across your site. Normally the archive page just has a number for the comments, not the "Comments" text itself so I had to modify my theme’s css a bit to accommodate the extra width required in this column.

That’s it :) Looks more daunting in hindsight actually. It would be much nicer if BE.NET had Disqus integrated into the standard build as an option.

Oh, and one more thing, something I have always wanted, comments on BE.NET pages. With the default BE.NET commenting system this is not possible, but with similar Disqus modifications, it is possible to have Disqus comments on your BE.NET pages also :)

Here are the steps I took to enable this:

  1. Add the following lines under the AdminLinks section of \page.aspx: Once again, yours will vary slightly and can be retrieved from the first snippet at http://disqus.com/comments/universal. There is a little bit of extra code here to make the comments appear only after the link is clicked (for tidyness sake). This is not necessary though.
  2. Add the following property to \page.aspx.cs:

And enjoy :)
Hamish

Categories:   BlogEngine.NET
Actions:   E-mail | Permalink | Comments