【问题标题】:Feature toggling MVC Web Api功能切换 MVC Web Api
【发布时间】:2016-06-23 17:55:04
【问题描述】:

是否可以在 MVC Web API 中使用Feature Toggling

我想限制在 API 功能完成之前调用某些控制器操作。

【问题讨论】:

    标签: asp.net-mvc asp.net-web-api2 featuretoggle


    【解决方案1】:

    建议可以创建一个自定义功能操作过滤器。可能是这样的:

    public class FeatureAttribute : ActionFilterAttribute
    {
        public string RequiredFeature { get; set; }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!Settings.Default.SomeFeature)
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {{ "Controller", "Home" }, { "Action", "Index" } });
            }
            base.OnActionExecuting(filterContext);
        }
    }
    

    然后在你的控制器上添加属性:

    [Feature(RequiredFeature = "Somefeature")]
    public ActionResult ActionNotYetReady()
    {
        return View();   
    }
    

    这是一个简单的示例,但只要关闭给定功能的功能切换/配置设置,就会将用户重定向到特定的控制器操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-12
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多