2012-11-02 32 views
4

我已經做了相當多的研究,並測試了1.4和2.0版本的FluentSecurity庫,我似乎不能夠使用的配置模式:流利的安全性 - 配置參數控制器動作

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

當我控制器操作需要一個參數,如:

public ActionResult GetCustomer(int customerID) 

當前支持這種類型的配置?如果是這樣,我如何針對具有必需參數的操作實施角色要求?

回答

2

我在問同樣的問題。目前,您可以傳遞參數的默認值。

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

其中HomeController是:

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

我建議使用最簡單的事情成爲可能。由於該值完全被忽略,因此可以將值傳遞爲「」,0或false。無論在你的情況下感覺最好。 –