This project is read-only.

Please help.

May 18, 2016 at 8:35 PM

I've re-worded this to try and get a solution.

I'm using BlogEngine.NET 3.3. I have a requirement to show 300 Characters of the posts in the blog and then the registered user will then click the post name to read the rest.

I would like to un-registered users (Anonymous users) to be able to see the 300 characters but when they try to read the full content of the post they get some text saying "Please Register to see this content".

I've scoured the net trying to find out if someone has achieved this before. I found the below code. It says to put it into the App_Code/Extensions folder as a .cs to enable it. However, in 3.3 there isn't an extensions folder in App_Code. There is one here in here BlogEngine.Core\Web\Extensions. I've tried putting the below code into the web\extensions folder and it appears to do something. It hides all of my published posts.

Could someone please help me with this?

    using System;

    using System.Data;

    using System.Configuration;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.HtmlControls;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using BlogEngine.Core;

    using BlogEngine.Core.Web.Controls;

    using System.Collections.Generic;


    /// <summary>

    /// Summary description for PostSecurity

    /// </summary>

    [Extension("Checks to see if a user can see this blog post.",

            "1.0", "<a href=\"\"></a>")]

    public class PostSecurity


    static protected ExtensionSettings settings = null;


    public PostSecurity()


        Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);


        ExtensionSettings s = new ExtensionSettings("PostSecurity");


        s.AddParameter("Role", "Role", 50, true);

        s.AddParameter("Category", "Category", 50);


        // describe specific rules for entering parameters

        s.Help = "Checks to see if the user has any of those roles before    displaying the post. ";

        s.Help += "You can associate a role with a specific category. ";

        s.Help += "All posts having this category will require that the user have the role. ";

        s.Help += "A parameter with only a role without a category will enable to filter all posts to this role. ";


        s.AddValues(new string[] { "Registered", "" });



        settings = ExtensionManager.GetSettings("PostSecurity");



    protected void Post_Serving(object sender, ServingEventArgs e)


        Post post = (Post)sender;

        bool continu = false;


        MembershipUser user = Membership.GetUser();


        continu = user != null;


        if (user != null)


            List<string> categories = new List<string>();

            foreach (Category cat in post.Categories)



            string[] r = Roles.GetRolesForUser();


            List<string> roles = new List<string>(r);


            DataTable table = settings.GetDataTable();

            foreach (DataRow row in table.Rows)


                if (string.IsNullOrEmpty((string)row["Category"]))

                    continu &= roles.Contains((string)row["Role"]);



                    if (categories.Contains((string)row["Category"]))

                        continu &= roles.Contains((string)row["Role"]);





        e.Cancel = !continu;


May 19, 2016 at 4:31 AM
Edited May 19, 2016 at 4:36 AM
You don't need to code to restrict post to number of characters, just check "only show description" in settings, default is 300.

To lock post details from anonymous users, you'll need an extension that runs on post serving and checks if user is authenticated.
You need to use Visual studio to add class and compile project for this. All extensions are in the BlogEngine.NET/Custom/Extensions.

Code below would check authentication and redirect to login if anonymous:
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
using System.Web;

[Extension("Secure post", "1.0", "BlogEngine.NET")]
public class SecurePost
    static SecurePost()
        Post.Serving += Post_Serving;

    private static void Post_Serving(object sender, ServingEventArgs e)
        if(e.Location == ServingLocation.SinglePost)
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
You need to add SecurePost.cs class, paste this code and build.
Event registration line should be "plus equals", CodePlex editor doesn't like "plus".
May 19, 2016 at 7:54 AM
Thank you so much!!! This is exactly what i needed.