Sitefinity ASP.NET CMS - Content Management System

KB Article

Home >  Support >  Knowledge Base >  KB Article
How to require users to log in before posting comments - ID#1048
Rating: Not rated
Last Modified: 7/11/2008
Related categories: Modules;

Article information

Article relates to

 Sitefinity 3.2 Hotfix 1616

Created by

 Penka Ivanova

Last modified by

 Rebecca


To implement login for posting comments to blogs, you need to create your own control that extends the base class Telerik.Blogs.WebControls.BlogCommentsList.

This is how to do it:

1. In the CreateChildControls method of the BlogCommentsList extender, subscribe Submit button to the Click event and then add an event handler:

protected override void CreateChildControls() 
        { 
            if (this.Page == null
                this.Page = new Page(); 
 
            base.CreateChildControls(); 
 
            this.Container.SubmitButton.Click += new EventHandler(SubmitButton_Click)
        } 

2. In the event handler, check whether the user is authenticated:

void SubmitButton_Click(object sender, EventArgs e) 
        { 
            if (!this.Page.User.Identity.IsAuthenticated) 
            { 
                this.ParentID = Guid.Empty; 
                this.Page.Response.Redirect("~/login.aspx"); 
            } 
        } 

3. Modify the ~/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx template to use BlogCommentsListExtender instead of the old BlogCommentsList custom control.

... 
<%@ Register Assembly="App_Code" Namespace="Telerik.Blogs.WebControls" TagPrefix="sfWeb" %> 
... 
 
<sfWeb:BlogCommentsListExtender ID="commentsList" runat="server" CssClass="sf_commentsList"
        ... 
</sfWeb:BlogCommentsListExtender> 

See attachment for full example.

You can use the same approach to achieve the same functionality for the CommentsList control. Note that the extender there should inherit the Telerik.Cms.Engine.WebControls.CommentsList base class.


Article Files

  • BlogsCommentsListExtender.zip



  • Article Comments

    There are no comments yet.
    Please Sign In to rate this article or to add it to your favorites.