Require user account for commenting

Topics: ASP.NET 2.0, Controls
Nov 18, 2010 at 9:07 PM

I have been checking out BlogEngine.NET and looking to use it for a new blog that I am about to launch.  One requirement that I am being asked to meet by my client is that any visitor that wants to submit a comment must first setup a user account and profile.  Has anyone done that with BlogEngine.NET before?  If so, did you need to modify the base code or is there an extension you used?  Also, the client wants to use their own user membership system which is similar to OpenID for these user accounts, I am thinking that I would have to create some sort of plugin / extension to make that work.  Has anyone done something like this before?  Thanks!

Coordinator
Nov 19, 2010 at 6:46 AM

In the upcoming BE 2.0, there's a way to disallow visitors who are not logged in from leaving comments.  It's part of a new Rights system.  Logged out users are part of the "Anonymous" role.  You can assign or remove rights such as "creating a comment" to the Anonymous role.

Even in a pre-BE 2.0 version without this Rights system, you can still modify BE to only allow logged in users to leave a comment.  It's actually a couple of small modifications in CommentView.ascx.cs in the "User controls" folder.

In RaiseCallbackEvent(), add the highlighted part shown below

if (!BlogSettings.Instance.IsCommentsEnabled || !Page.User.Identity.IsAuthenticated)
    return;

.... and in the same file, in Page_Load, a similar change is needed:

if (BlogSettings.Instance.IsCommentsEnabled && Page.User.Identity.IsAuthenticated)

.......... for a different Membership system, maybe someone has already done something.  BE uses the ASP.NET Membership provider system, which is actually flexible in that you can swap it out for a different membership system.  BE has already actually done this with the XmlMembershipProvider and DbMembershipProvider.  You could create a new Membership system based off of the code in these providers ... and tailor it for your needs.

Nov 22, 2010 at 8:02 PM

Ben - Thanks for the quick reply.  Also, thanks for insight into the new Rights system that will be available in future releases of BlogEngine.NET.

I have been successful deploying and modifying BE to accomplish the requirements. Thanks!