Examples on new BlogEngine.NET 1.3 features

Dec 23, 2007

There is a lot of new features on almost every objects in the BlogEngine.NET code base, so here are a few examples on how to take advantage of some of them. I’ll put up some new videos soon highlighting some of these features.

User control injection with parameters

The user control injection feature introduced in version 1.2 has been upgraded, so that it now let’s you insert property values. Let’s imagine you have a user control called poll.ascx with two public properties called Name (string) and MaxAnswers (int). You can now set those properties from the editor by separating the properties with a semicolon like this:

[ usercontrol: ~/poll.ascx Name=Name of poll; MaxAnswers=200]

JavaScript handler

The new JavaScript handler minifies and HTTP compresses .js files. You can serve your own .js files through the handler easily from your theme. The method that converts the original path to the .js file into the new js.axd handler is located at the BlogBasePage. So if you from the site.master need to add a custom JavaScript you can do it like so:

<script type="text/javascript" src="<%=(Page as BlogEngine.Core.Web.Controls.BlogBasePage).ResolveScriptUrl("/script.js")%>"></script>

Also, the JavaScript handler can function as a proxy between your blog and a remote JavaScript like the Google AdSense script. By feeding an absolute URL into the ResolvescriptUrl method, the handler now caches the script for three days and serves it minified and HTTP compressed. This proxy feature was created to mitigate the performance hit a site have by including remote scripts that are slow.

I use a remote script on this site that is ~1 second to respond to the request and it isn’t minified or compressed, so the load time of this page is 1 second faster with the new JavaScript handler.

TagCloud update

Some people have a lot of tags and a lot of these tags only contain 1 post. That can clutter the TagCloud, so now you have the ability to specify how many posts a tag should contain as a minimum to be shown in the TagCloud. The default is 1 post, but you can change it in your theme like so:

<blog:TagCloud MinimumPosts="2" runat="server" />

Extensions and CancelEventArgs

The System.ComponentModel.CancelEventArgs are now used for a various different events. It let’s you cancel an action like adding comments or receiving trackbacks. Here is what to do in order to take advantage of the new model:

// constructor
public MyExtension()
{
 TrackbackHandler.Received += new EventHandler<CancelEventArgs>(TrackbackHandler_Received);
}

// event handler
void TrackbackHandler_Received(object sender, CancelEventArgs e)
{
  if (HttpContext.Current.Request.UserHostAddress == "123.456.78.90")
     e.Cancel = true;
}

This is an example of how to cancel a trackback request from being processed based on the IP address of the requesting website.

More info will follow here, on the BlogEngine.NET website and at Al Nyveldt's blog.

* $4.95/month BlogEngine.net Hosting – Click Here!

Comments (4) -

James Skemp
James Skemp United States
12/27/2007 4:20:30 PM #

Very cool to hear about the TagCloud update. I've updated, but haven't had time to really dig into what's now available.

Any plans for a page where we can view all tags used?

That is, instead of even having them display in the navigation structure, we can just direct them to one page that only has the tags, like how the Archive currently works, save without the individual posts listed below? http://blog.madskristensen.dk/archive.aspx

Also (sorry Mads, wrong place for it, but Codeplex has been acting up lately), I just noticed that http://blog.madskristensen.dk/category/ doesn't seem to work - a truncation from blog.madskristensen.dk/category/BlogEngine.aspx ; seems like it should redirect to either the Archive, or a page just listing the categories.

Finally, getting back on task ;), great post - these are exactly the kinds of examples that the wiki was missing, that are really, I think, *extremely* helpful.

Have a great New Years (and nice hat)!

~James

Cristiano
Cristiano Italy
12/31/2007 2:42:09 PM #

Released [b]BBCodeToolbar extension[b] (rel. 1.3 compatible).

BBCodeTolbar Extension replace the BBCode label at the top right corner of the comment textarea with a BBCode Buttons Toolbar. More info at:

www.cristianofino.net/.../...BlogEngineNET-13.aspx

Happy New Year, Mads

Paul Tumelty
Paul Tumelty United Kingdom
1/9/2008 4:04:32 PM #

Just stumbled across BlogEngine.Net today and have been very impressed. I tried to do something similar to the User Control injection a year or two ago and never managed to get it working properly. I havent tried it yet, but the samples look just like what I was trying to do.

Looking forward to the next releases and would love to contribute to the project once I'm familiar with the codebase.

Thanks, Paul.

Patrick
Patrick United States
5/20/2008 7:05:18 PM #

Does the control injection let you pass in strings instead of a number as you did? I can't seem to get this to function properly.

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.