Adding Facebook Comments to BlogEngine.Net

15. November 2013 00:03 by Jay Grossman in   //  Tags: , ,   //   Comments (0)

This blog runs using the open source platform using ASP.Net 4.0. So far I have been pretty happy with the features provided overall, as it was pretty straight forward to set up and there are many themes/widgets.

The issue I had with using the out of the box comments system was seeing about 15 spams comments posted a day. I've seen some of the bigger blogs use Facebook Comments and they had less of the spammy junk, like ESPN in the screenshot below:


Since I couldn't find a pre-canned BlogEngine widget available using Facebook comments, I needed to use Facebook Comments plugin to add this functionality.  I was able to insert the following code into PostView.ascx of my theme to implement Facebook comments:

    <fb:comments-count href="<%=Post.PermaLink %>"></fb:comments-count> <%=Resources.labels.comments %>
    <div id="fb-root"></div>
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); = id;
            js.src = "//";
            fjs.parentNode.insertBefore(js, fjs);
        } (document, 'script''facebook-jssdk'));
    <div class="fb-comments" data-href="<%=Post.PermaLink %>" data-width="470" data-num-posts="10"></div>

Since I wanted the comments box to appear only on the post page (and not on the homepage), I wrapped the Facebook markup in if statement below:

<% if (Request.Url.ToString().ToLower().IndexOf("post.aspx") >0) {%>
<% %> 

UPDATE (in 2020):

I wound up removing the functionality described in this post due the volume of spam posts in Facebook comments.


About the author

Jay Grossman

techie / entrepreneur that enjoys:
 1) my kids + awesome wife
 2) building software projects/products
 3) digging for gold in data sets
 4) my various day jobs
 5) rooting for my Boston sports teams:
    New England PatriotsBoston Red SoxBoston CelticsBoston Bruins

Month List