The Commentor extension for BlogEngine.Net written by rtur is a great extension for catching comment spam on the blog. Unfortunately the custom rules you can apply to comments only support a Block or Allow action.
What I want is to prevent the comments being saved at all if a manual rule has been violated. This is better for my needs as I don’t need to clean up the comments on the blog and I don’t get hassled by constant emails regarding comments that require moderation.
The changes to the extension to support this are relatively minor.
First is a change to the User controls\Commentor\Settings.aspx user control. The action dropdown now has a Delete action.
<td>
<asp:DropDownList ID="ddAction" runat="server">
<asp:ListItem Text="Block" Value="Block" Selected=true></asp:ListItem>
<asp:ListItem Text="Allow" Value="Allow" Selected=false></asp:ListItem>
<asp:ListItem Text="Delete" Value="Delete" Selected=false></asp:ListItem>
</asp:DropDownList>
</td>
The next set of changes were to implement the Delete action in the App_Code\Extensions\Commentor.cs class.
The ManualFilter enum definition has been extended to include the Delete action.
private enum ManualFilter { None, Block, Allow, Delete }
The Post_AddingComment method now supports this enum value in its processing of a new comment.
// validate against filter
switch (CheckFilter(comment))
{
case ManualFilter.Block:
comment.IsApproved = false;
return;
case ManualFilter.Allow:
comment.IsApproved = true;
return;
case ManualFilter.Delete:
comment.IsApproved = false;
e.Cancel = true;
return;
default:
break;
}
And finally, the CheckRow method has been updated to use the new Delete action.
if (match)
{
if (action == "Block")
return ManualFilter.Block;
if (action == "Delete")
return ManualFilter.Delete;
return ManualFilter.Allow;
}
Make these changes and you will be able to use delete actions to prevent comments from being saved.
NOTE: The settings for existing rules will need to be updated where they are stored (most likely in a database or xml file) in order for them to use the Delete action. A restart of the website will be required to pick up these changes that were made directly against the settings datastore. Alternatively you will need to delete and recreate any existing custom rules that you want to use the Delete action with.
My Commentor extension settings now look like the following.

Tags: BlogEngine.Net