title: Custom authorize attribute with windows authentication and identity empty
body: <p>I create own implementation of authorize attribute:</p>
  
  <pre><code>public class CustomAuthorizeAttribute : AuthorizeAttribute
  {
      /// &lt;summary&gt;
      /// Log4net logger
      /// &lt;/summary&gt;
      private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  
      protected override bool AuthorizeCore(HttpContextBase httpContext)
      {
          logger.Info("User name IsAuthenticated " + httpContext.User.Identity.IsAuthenticated);
          logger.Info("User name " + httpContext.User.Identity.Name);
          if (httpContext.User.Identity.IsAuthenticated)
          {
              if (!string.IsNullOrEmpty(httpContext.User.Identity.Name))
              {
                  logger.Info("User name " + httpContext.User.Identity.Name);
                  string[] domainUser = httpContext.User.Identity.Name.Split('\\');
                  if (domainUser.Count() == 2)
                  {
                      if (domainUser[0].Equals("MyDomain", StringComparison.OrdinalIgnoreCase))
                      {
                          LdapService ldap = new LdapService();
                          return ldap.IsUserInAd(domainUser[1]);
                      }
                  }
              }
          }
          return base.AuthorizeCore(httpContext);
      }
  
      protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
      {
          base.HandleUnauthorizedRequest(filterContext);
          filterContext.Result = new RedirectResult("~/Error/Unauthorized");
      }
  }
  </code></pre>
  
  <p>and set this attribute for controller:</p>
  
  <pre><code>[CustomAuthorize]
  public class AccountController : Controller
  {
      /// &lt;summary&gt;
      /// Log4net logger
      /// &lt;/summary&gt;
      private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  
      /// &lt;summary&gt;
      /// Index method run on start of the Account view.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;Action Result.&lt;/returns&gt;
      [CustomAuthorize]
      public ActionResult Index()
      {
          WindowsIdentity identity = System.Web.HttpContext.Current.Request.LogonUserIdentity;
          logger.Info("User name IsAuthenticated " + identity.IsAuthenticated);
          logger.Info("User name " + identity.Name);
          if (identity != null)
          {
              LdapService ldap = new LdapService();
              string[] domainUser = identity.Name.Split('\\');
              if (domainUser[1].Equals(AccessHelper.ReceptionUserName))
              {
                  return RedirectToAction("Index", "Guest");
              }
              else
                  if (ldap.IsUserInReception(domainUser[1]))
                  {
                      return RedirectToAction("Index", "Reception");
                  }
                  else
                  {
                      return RedirectToAction("Index", "Employee");
                  }
          }
          return RedirectToAction("Index", "Employee");
      }
  </code></pre>
  
  <p>in web config I set windows auth...:</p>
  
  <pre><code> &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="2.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="PreserveLoginUrl" value="true" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
      &lt;add key="autoFormsAuthentication" value="false" /&gt;
      &lt;add key="enableSimpleMembership" value="false" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
      &lt;globalization uiCulture="en-GB" culture="en-GB" /&gt;
      &lt;authentication mode="Windows" /&gt;
       &lt;identity impersonate="true" /&gt;
  </code></pre>
  
  <p>When I deploy my Asp.net mvc 4 app for server iis and run I have logged that I am not authenticated and User is empty. Why my page not see that I should be auth by windows credentials ?</p>