title: ASP.NET MVC 5 OWIN Area Authentication
body: <p>I am building an <code>ASP.NET MVC 5</code> based web site that uses <code>OWIN</code> based authentication. I have created a new <code>Area</code> in the application for administrator panel. I would like to have a different login page than that of the normal user. </p>
  
  <p>For instance, when i go to <code>http://site/admin/home/index</code> it should check for authorization and redirect to <code>http://site/admin/account/login</code> instead of going to site user login page. </p>
  
  <p>I have already tried implementing a custom <code>Authorize</code> attribute. However, I somehow feel that it's not the right approach.</p>
  
  <p>Could someone suggest a better or more right solution for this?</p>
  
  <p><strong>Edit:</strong> Custom attribute implementation</p>
  
  <pre><code>public class AuthorizeAreaAttribute : AuthorizeAttribute
  {
      public string Url { get; set; }
  
      public override void OnAuthorization(AuthorizationContext filterContext)
      {
          if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
          {
              filterContext.HttpContext.Response.Redirect(Url);
              filterContext.HttpContext.Response.End();
          }
          base.OnAuthorization(filterContext);
      }
  }
  </code></pre>