.Net MVC output caching by cookie value

A way to control caching provided by ASP.Net is to use a cookie as a parameter. The following example shows how to do this:

1) Create the following method in global.asax

public override string GetVaryByCustomString(HttpContext context, string arg)
{
     if (arg.ToLower() == "cookieuser")
     {
        var cookie = context.Request.Cookies["Your cookie name here"];

        if (cookie != null) { 
           return cookie.Value;
        }
     }
     return base.GetVaryByCustomString(context, arg);
}

2) Add a cache section to web.config

<caching>
  <outputCacheSettings>
      <outputCacheProfiles>
         <add name="CacheOnServer" duration="3600" varyByParam="none" varyByCustom="CookieUser" location="Server" varyByContentEncoding="true" enabled="true" />
         <add name="CacheOnClient" duration="3600" varyByParam="none" varyByCustom="CookieUser" location="Client" varyByContentEncoding="true" enabled="true" />
      </outputCacheProfiles>
  </outputCacheSettings>
</caching>     

3) Decorate the controller

[OutputCache(CacheProfile = "CacheOnServer")]
public ActionResult SomeAction()
{
..
}