Search code examples
asp.net-mvcauthenticationauthorize-attribute

Authorize attribute on HomeController forces login on AllowAnonymous controller


The HomeController of my mvc 5 application has an [Authorize] attribute

[Authorize]
public class HomeController : Controller

The SimpleController is the followin (a simple test):

[AllowAnonymous]
public class SimpleController : Controller
{
    // GET: Simple
    public ActionResult Index()
    {
        return View();
    }
}

Why do I have to log in when I browse straight to http://url/simple/index?

I have to extra "force authentication code" or filters registered.

When I remove the [Authorize] on the HomeController, the SimpleController works fine, without the need to log in


Solution

  • You may have configured Global Authorization filter in FilterConfig.cs, located in App_Start folder

    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new AuthorizeAttribute());
        }
    }