Password Protected Extension

26. August 2009 4:04 PM

Back to few days ago, a friend of mine who also using .NET BlogEngine was asking me about how to modify the code to make it support password protected post/page.

After I look into details about how am I going to kick start... and I found the best implementation is writing an 'Extension'. That how the 'PasswordProtected' extension was borned! See the sample post here!

Before you can enjoy the password protection features, you are require to defined more roles besides both the existing 'Administrators' and 'Editors' in the \App_Data\roles.xml data file as show in the screen shot below,

Note, after you have updated the roles.xml, you are require to restart the IIS before you can see the new defined role appear on the users screen. Then, you are begin to create more users under any others roles other then 'Administrators' and 'Editors'. As the best practice is using email address as the login ID, and further defined the nickname under the respective profile, so a correct nickname will be display on the comments instead the login ID (email address).

Next is download this extension and upload to your respective .NET BlogEngine folders.

  1.   Copy the 'PasswordProtected.cs' source fiel to '\\blog\App_Code\Extensions' folder.
  2.   Copy the 'protected.png' image file to '\\pics' folder (you may change this image).

 

Last thing you need to know is the syntax... a syntax that make your post/page become password protected!

  [protected:on|off;roles:role1,role2,role3]

Below is some of the self explain combination,

  • Turn the password protection off. 
      [protected:off]
  • Sample syntax for password protection enabled and only limit to all users with under role of 'role2'.
      [protected:on;roles:role2]
  • Another sample syntax with password protection enabled and limit to all users with under role of 'role1' and 'role3'.
      [protected:on;roles:role1,role3]


Note
, both 'Administrators' and 'Editors' role will overwrite the defined role in the above syntax.


 

 PasswordProtected.v1.0.826.1.zip (37.48 kb)

BlogEngine.NET ,

Password Protected Demo Post

26. August 2009 1:44 PM

This is a protected post, you are require to login prior read this post.

BlogEngine.NET ,

Code Formatter Extension

25. March 2009 1:00 PM

When I composing the Headline News Control topic last week, and I keep suffering from formatting the sample code with the 'Code Formatter Extension' developed by manoli. After spent some time digging in and out from Google, and finally I found a posting about the missing CodeFormatterExtension.cs was actually put into a wrong folder (App_Code\Extensions\CodeFormatter) with a wrong filename (CodeFormatter.cs) too.

Next, I encounter another new problem... that is the code snippet does not formatted at all. So, I continue to digging through Google again. Last, I found this posting! Again... it does not solve my problem! Therefore, I took a visit manoli website and try out the version in his website and compare the formatted code with the output from the 'Code Formatter Extension' I have, and I notice there are differents! Hence, I step into the code and fixed it up and proceed to added the code, so that it will automatic include the missing CSS (csharp.css that I download from manoli website) link tag in the output HTML.

After a long struggling with this 'Code Formatter Extension', finally I get everything up and running with a minor touch up the csharp.css to have a better code snippet window being render in the blog. But, there is one problem I failed to resolve it! that is the alternative line background color does not cover the full code snippet when the code is too long as show in sample below.

   1:      /// <summary>
   2:      /// An event that handles ServingEventArgs
   3:      /// </summary>
   4:      /// <param name="sender"></param>
   5:      /// <param name="e"></param>
   6:      void ServingContent(object sender, ServingEventArgs e)
   7:      {
   8:        if (e.Body.Contains("XYZ"))
   9:        {
  10:            HtmlLink cssLink = new HtmlLink();
  11:            cssLink.Attributes["rel"] = "stylesheet";
  12:            cssLink.Attributes["type"] = "text/css";
  13:            cssLink.Attributes["href"] = String.Concat(Utils.RelativeWebRoot, "CodeFormatter/csharp.css");
  14:            System.Web.UI.Page page = (System.Web.UI.Page)HttpContext.Current.CurrentHandler;
  15:            page.Header.Controls.Add(cssLink);
  16:            
  17:            e.Body = codeRegex.Replace(e.Body, new MatchEvaluator(CodeEvaluator));
  18:            e.Body = codeBeginTagRegex.Replace(e.Body, @"<div class=""code"">");
  19:            e.Body = codeEndTagRegex.Replace(e.Body, @"</div>");
  20:        }
  21:      } 

 

To Do...

  1. Unzip the CodeFormatterExtensions.zip
  2. Copy the respective files into your blog root directory.

 

Syntaxs... 

Here are those syntax supported by this 'Code Formatter Extensions'

[code:c#|vb|js|html|xml|tsql|msh;ln=on|off;alt=on|off]

   Put your code snippet here

[⁄code]

 

Since I have spent the time to fixed most the problem in this 'Code Formatter Extension', and wish to save those BlogEngine.NET newbies time to fixed this problem...  I am upload the updated copy of 'Code Formatter Extensions' for those wish to download and use it. Do enjoy this extension origin from manoli.  

 

CodeFormatterExtensions.zip (19.13 kb)

BlogEngine.NET