I'm implementing a custom authorize filter that inherits from AuthorizeAttribute. After my research I found out action filters are cached so they are instantiated only once.
Here is my question. If I implement and use a custom action filter like below, it shouldn't work correctly because it would be instantiated once and never call constructor again. But when I tested, it worked well so I'm thinking there is something I don't know.
Can anyone explain this(action filter life cycle?) clearly?
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
private readonly string value = string.Empty;
public CustomAuthorizeAttribute(string value)
{
this.value = value;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
// Do something with this.value
}
}
public class HomeController : Controller
{
[CustomAuthorize("ACCESS_INDEX")]
public ActionResult Index()
{
}
[CustomAuthorize("ACCESS_LOGIN")]
public ActionResult Login()
{
}
}