It’s been 6 months since the last release of BlogEngine.NET, but now the wait is over. You can download BlogEngine.NET 1.4 here.

What’s new?

A lot of new features and tweaks have been implemented in version 1.4. On top of all the tasks in the roadmap, more than 140 work items reported by the community made it. That’s a lot.

Here are some of my favourite new features:

  • Universal database provider (MySQL, SQL Server, VistaDB, Oracle etc.)
  • Drag ‘n drop widget framework (prototype video)
  • Author profiles using ASP.NET profile provider
  • Subcategories
  • Password encryption
  • Better performance
  • Tag selector in control panel
  • Semantic formats (FOAF, SIOC and APML)

You can read more about the new BlogEngine.NET 1.4 features at the official release note. If you wish to upgrade, then Al Nyveldt have written an excellent upgrade guide you should check out.

Next step

The next couple of weeks will be spent recording screencasts of the new features and give examples on how to write widgets. There's a lot of ground to cover with all the new features and possibilities for developers to utilize.

I hope you will enjoy this new version. It has taken a lot of hard work by the BlogEngine.NET team and I know they are very happy about the release - I know I am.

I’ve known about the IHttpAsyncHandler interface for a long time, but never really had the time to play around with it. After a brief web search I realized that not many people have. There are no easy to understand articles or blog posts on the subject, so I thought I’d investigate and share.

Basically, the IHttpAsyncHandler interface allows you to serve content asynchronously from a HTTP handler. This is great when you need to free up the worker thread to do processing like IO work etc. ASP.NET actually uses fewer threads when it runs asynchronously, which is great for performance and scalability. That’s because each thread is returned much faster to the thread pool.

The IHttpAsyncHandler is very similar to IHttpHandler interface, but with two extra methods to override – BeginProcessRequest and EndProcessRequest. From there you invoke a delegate to handle the processing asynchronously. It sounds complicated, but it really isn’t. Here is an example that removes the complicated stuff and gives you one single method to modify.

The code

The example is a handler that is used to serve files for download. Serving a file requires IO access and therefore it is a great candidate for asynchronous serving. As you can see, the ServeContent method is all there is needed for the specific task of serving files. Just modify it to whatever purpose you find fit.

public class AsyncFileHandler : IHttpAsyncHandler

{

 

  /// <summary>

  /// You only have to modify this method.

  /// </summary>

  private void ServeContent(HttpContext context)

  {

    string filePath = context.Server.MapPath(context.Request.QueryString.ToString());

    if (File.Exists(filePath))

    {

      context.Response.TransmitFile(filePath);

    }

    else

    {

      context.Response.Write("File does not exist");

      context.Response.StatusCode = 404;

      context.Response.End();

    }

  }

 

  #region IHttpAsyncHandler Members

 

  private AsyncProcessorDelegate _Delegate;

  protected delegate void AsyncProcessorDelegate(HttpContext context);

 

  public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)

  {

    _Delegate = new AsyncProcessorDelegate(ProcessRequest);

    return _Delegate.BeginInvoke(context, cb, extraData);

  }

 

  public void EndProcessRequest(IAsyncResult result)

  {

    _Delegate.EndInvoke(result);

  }

 

  #endregion

 

  #region IHttpHandler Members

 

  public bool IsReusable

  {

    get { return true; }

  }

 

  public void ProcessRequest(HttpContext context)

  {

    ServeContent(context);

  }

 

  #endregion

}

There is actually very little reason to use the IHttpHandler interface anymore.

Important! This is an example on how to use the IHttpAsyncHandler and not to serve files. Do not use the file serving method in production code. 

Download

Download the AsyncFileHandler.cs file below and put it in the App_Code directory. Then add this XML fragment to the web.config:

<httpHandlers>
  <add verb="*" path="*file.axd" type="AsyncFileHandler" />
</httpHandlers> 

AsyncFileHandler.zip (1,14 kb)