Dmi*_*kin 14 .net c# asp.net asp.net-mvc asp.net-mvc-3
有条件地禁用ASP.NET MVC控制器的最佳方法是什么?
如果web.config中的某些值为"true",我希望能够访问控制器操作,如果它是"false",则我想访问404
我应该写自己的属性吗?
更新:寻找比动作过滤器属性更优雅的解决方案(能够将非常量参数传递给属性构造函数)
    [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);
            }
        }
    }