【问题标题】:Fluent Security - configuring parameterized controller actionsFluent Security - 配置参数化控制器操作
【发布时间】:2012-11-02 22:27:14
【问题描述】:

我做了相当多的研究并测试了 FluentSecurity 库的 1.4 和 2.0 版本,但我似乎无法使用配置模式:

configuration.For<MyController>(x => x.GetCustomer())
  .RequireRole(appRoles);

当我的控制器动作需要一个参数时,例如:

public ActionResult GetCustomer(int customerID)

目前是否支持这种类型的配置?如果是这样,我如何针对具有必需参数的操作实施角色要求?

【问题讨论】:

    标签: c# fluent-security


    【解决方案1】:

    我也在问同样的问题。目前,您可以为参数传入默认值。

    configuration
        .For<HomeController>(x => x.Index(default(string)))
        .DenyAnonymousAccess();
    

    HomeController 在哪里:

    public ActionResult Index(string id)
    {
        return View();
    }
    

    【讨论】:

    • 我建议尽可能使用最简单的方法。由于该值被完全忽略,您可以将值传递给它,例如“”、0 或 false。无论您的情况如何。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    相关资源
    最近更新 更多