Every now and then I need some modules, components or code snippets for my various projects only to find out on Google that they don’t exist. No one have invented/published/written them and that’s a shame. Here is a list of some of the things I’d like to have someone (other than myself) write and publish as open source:

1. Silverlight XHTML editor

All the JavaScript based editors such as TinyMCE, FCKeditor and FreeTextBox are all pretty nice, but they are still not quite there. With Silverlight we can now make something truly spectacular. Think of adding images to a blog post and harvest all the imaging power of the System.Drawing namespace right there. It would be able to build something better, faster, nicer (XAML for God sake!) and totally integrated into your ASP.NET application.

2. OpenID membership provider for ASP.NET

OpenID is a promising authentication technology that I would like to play with in various projects including BlogEngine.NET. There are already some ASP.NET controls and libraries out there, but no membership provider. I don’t want to use a library and then have to write the membership provider on top of that. I want a single C# file that I can just register in the web.config and voila!

It doesn’t matter if it uses SQL or XML because that can fairly easily be converted and I need both.

3. ASP.NET MonsterID implementation

A MonsterID is an auto generated image that is based on an e-mail address. The same e-mail always produces the same monster. The image of a monster is based on various different pieces such as body, 2 eyes, hair, arms and legs. These images come in multiple varieties and is put together based on the e-mail address and an algorithm. The monster parts can be from the Combinatoric.Critters website or from the MonsterID download for PHP. The idea is that it should be used instead of Identicons and use the e-mail instead of the IP address.

What I need is a single HttpHandler that renders the image and serves it based on a hashed e-mail address provided from the query string. It must save the rendered image on disk, so it doesn’t have to recreate it every time it loads.

So if you are bored this summer, why not create something that doesn’t exist and claim the fame?

People have asked me how we build the extension model into BlogEngine.NET. There’s nothing to it - really, there isn’t.

You need one small class and 14 lines of code in the global.asax. That is all you need to make your ASP.NET application extendable. An extension is just a normal class that is somehow marked as being an extension. No magic is needed.

The scenario I liked best was one where you could just drop your custom extension into the App_Code folder and then it would just work. Reflection would take care of creating an instance of the extension, but we need a way to separate the extensions from all other classes in the App_Code folder. That’s where we need the small class.

The class

I decided it would make most sense to have all custom extensions be decorated with a custom attribute called Extension and then let global.asax activate them when the application starts. That would make the class definition of a custom extension look like this:

[Extension("description")]
public class MyCustomExtension

To do that, we need to write a very small class that inherits from System.Attribute and it looks like this:

public class ExtensionAttribute : System.Attribute
{
  /// <summary>
  /// Creates an instance of the attribute and assigns a description.
  /// </summary>
  public ExtensionAttribute(string description)
  {
    _Description = description;
  }

  private string _Description;
  /// <summary>
  /// Gets the description of the extension.
  /// </summary>
  public string Description
  {
    get { return _Description; }
  }
}

It’s a very simple class that just has a description property and that’s it. The description property is not really needed to implement extensions, so you can leave it out if you’d like.

Global.asax

Now we have our custom attribute, so it’s time to let global.asax use reflection to activate the extensions. This method iterates through all the types in the App_Code folder and when it finds a class that is decorated with the Extension attribute then it creates an instance of it.

void Application_Start(object sender, EventArgs e)
{
  Assembly a = Assembly.Load("__code");
  Type[] types = a.GetTypes();

  foreach (Type type in types)
  {     
    object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
    foreach (object attribute in attributes)
    {
      a.CreateInstance(type.FullName);
    }
  }
}

That’s it. Now your ASP.NET application handles custom extensions made by who ever wants to write them. There are many ways to customize this implementation. For instance, you can put the reflection code in the Begin_Request method instead of the Application_Start to let your extensions act as an HttpModule.

Download a custom extension (zip)