title: Derived from AuthorizeAttribute but User.Identity.Name is null unless using AuthorizeAttribute
body: <p>So I've created a custom authorize attribute I use in a few places that is derived from an abstract base class which is derived from <code>AuthorizeAttribute</code>:</p>
  
  <p>CustomAuthorizeAttributeBase.cs</p>
  
  <pre><code>public abstract class CustomAuthorizeAttributeBase : AuthorizeAttribute
  {
      public abstract string GetUsers();
      public abstract string GetRoles();
      protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
      {
          if (filterContext.IsChildAction)
          {
              return;
          }
          filterContext.Result =
              new RedirectToRouteResult(new RouteValueDictionary
              {
                  {"controller", "NotAuthorized"},
                  {"action", "Index"},
              });
      }
  
      protected override bool AuthorizeCore(HttpContextBase httpContext)
      {
          if (GetUsers().IndexOf(httpContext.User.Identity.Name, StringComparison.CurrentCultureIgnoreCase) &gt;= 0 ||
              GetRoles().Split(',').Any(s =&gt; httpContext.User.IsInRole(s)))
          {
              return true;
          }
          return false;
      }
  
  }
  </code></pre>
  
  <p>AreaLevelReadonly.cs</p>
  
  <pre><code>public class AreaLevelReadOnly : CustomAuthorizeAttributeBase
  {
      public override string GetUsers()
      {
          return ConfigurationManager.AppSettings["AreaReadonlyUsers"];
      }
  
      public override string GetRoles()
      {
          return ConfigurationManager.AppSettings["AreaReadonlyRoles"];
      }
  }
  </code></pre>
  
  <p>I also have some fairly simple code that gets me the currently logged in user:</p>
  
  <p>UserIdentity.cs</p>
  
  <pre><code>public class UserIdentity : IUserIdentity
  {
  
      public string GetUserName()
      {
          return HttpContext.Current.User.Identity.Name.Split('\\')[1];
      }
  }
  </code></pre>
  
  <p>However, when I add my AreaLevelReadonly attribute to my controllers, getUserName fails and returns an exception that <code>Name</code> is null. I agonized over it for about an hour before putting authorize attribute on there as well, at which point it magically started working again. So, what is so different on the implementation level that my attribute deriving from authorizeattribute doesn't cause the <code>Name</code> to be populated.</p>
  
  <p>Note: Windows authentication is on for the area, and the code works, but I don't understand why the Readonly attribute isn't enough to trigger authorization and population of the <code>HttpContext.Current.User.Identity.Name</code>.</p>
  
  <p>Edit: Working:</p>
  
  <pre><code>[AreaLevelReadonly]
  [Authorize]
  public class DeleteAreaDataController : Controller { 
      //etc 
      var username = _userIdentity.GetUserName(HttpContext);
      //etc
  }
  </code></pre>
  
  <p>Exception on name:</p>
  
  <pre><code>[AreaLevelReadonly]
  public class DeleteAreaDataController : Controller { 
      //etc
      var username = _userIdentity.GetUserName(HttpContext);
      //etc
  }
  </code></pre>