Posts Tagged ‘asp.net’

Is the Web Application Toolkit for Freemium Applications from Microsoft any good?

No Comments »

Microsoft recently released the “Web Application Toolkit for Freemium Applications” for building applications based on the freemium model. I am not a big fan of the Freemium model myself, but I thought it would be interesting to take a closer look at the toolkit anyway.

First off, let’s recap the freemium model. According to Wikipedia:

Freemium is a business model that works by offering basic Web services, or a basic downloadable digital product, for free, while charging a premium for advanced or special features.

Thus, to build applications for the freemium model, we need to be able to

  1. Have multiple feature sets and manage these
  2. Have users associated with one or more feature sets
  3. Have a user’s chosen feature sets reflect in the application GUI presented to the user
  4. Have a user’s chosen feature sets automatically reflect in the billing

It might also be nice to

  1. have users grouped into categories with catchy names and associate feature sets with each category
  2. be able to easily move users between categories, possibly by self-service

This is what the toolkit should ideally help us achieve.

The tools

In broad terms, the toolkit works on two concepts: features and SKUs, and it uses the ASP.NET Membership functionality to associate users to SKUs. SKUs are sets of features and each SKU has a unique identifier called a slug. SKUs are mapped to users by means of standard ASP.NET Roles having the same name as a SKU slug. Thus, there will be a “Gold” SKU identified by the slug “gold” and all users in the role “gold” are associated to the Gold SKU.

If you buy into this way of grouping features and associating them with users, the framework provides:

  • Page extension methods for displaying/hiding content based on the user’s SKU
  • Action attributes to allow or prevent the user from executing certain actions based on the SKU
  • A MVC 2 Area with controllers and views for managing SKUs
The verdict

The components described in the three bullets above are definitely valuable in any application based on the freemium model. However, their actual implementation leaves something to be desired. The provided functionality isn’t componentized properly and there is a general lack of extension points: to really use the toolkit, you need to buy into a lot of arbitrary design decisions which are unlikely to suit your application. Moreover, there is just a gust of code smell around it: views aren’t properly decoupled from business logic, no DI is used etc.

All in all the Web Application Toolkit for Freemium Applications is a nice initiative from Microsoft and it contains some relevant thoughts. If Microsoft decides to put some effort into the toolkit to provide extension points etc., it may even be able to kickstart your next freemium application. At the moment, however, the toolkit is pretty blunt. It is nothing more than a sample implementation which may provide inspiration but does not deserve to be called a toolkit.

The Web Application Toolkit for Freemium Applications is available on MSDN.


How to determine if an ASP.NET OutputCacheModule is enabled for your application

No Comments »

I recently had an issue with an ASP.NET application concerning output caching. I thought output caching was configured correctly, but apparently pages weren’t being served from the cache. So, what do you do? Well, I decided to find out for real, whether the System.Web.Caching.OutputCacheModule was being run. When the OutputCacheModule is initialized it will register event handlers on the HttpApplication’s ResolveRequestCache and UpdateRequestCache events. Thus, I set out to determine who was subscribing to these events at runtime.

After spending some quality time with Reflector and the debugger I discovered that the HttpApplication uses a somewhat internal scheme to organize the registered event handlers. You can get to the datastructure containing the handlers through the HttpApplication.Events property of type EventHandlerList. However, in order to get to the desired delegate, you have to index this property with the correct key. In this case, the key is a private static readonly field of HttpApplication! Enter System.Reflection.

The key for getting at the ResolveRequestCache is called EventResolveRequestCache (likewise, for UpdateRequestCache it is called EventUpdateRequestCache). Hence, we may add the following code to Global.asax.cs to get to the subscribing HttpModules:

private IEnumerable GetResolveRequestCacheSubscribers()
{
    Type httpapptype = typeof(HttpApplication);
    FieldInfo f = httpapptype.GetField("EventResolveRequestCache",
                                                    BindingFlags.Static |
                                                    BindingFlags.NonPublic);
    object eventResulveRequestCacheKey = f.GetValue(this);
    Delegate dels = Events[eventResulveRequestCacheKey];
    if(dels == null)
        return Enumerable.Empty();
    else
        return (from d in dels.GetInvocationList()
                    where d.Target != null && d.Target is IHttpModule
                select d.Target as IHttpModule);
}

Enjoy