What is the best way to disable ASP.NET MVC controller conditionally?
I want to have an access to the controller actions if some value in web.config is "true" and 404 if it's "false"
Should I write my own attribute?
UPDATE: Looking for more elegant solution than action filter attribute (with an ability to pass not constant parameter to attribute constructor)
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class CloseForSomeSettingAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool mySettingValue = MySettingManager.GetMySettingValue();
if (mySettingValue)
{
filterContext.Result = new HttpStatusCodeResult(404);
}
else
{
base.OnActionExecuting(filterContext);
}
}
}