如何为采用参数的方法配置Fluent Security策略



可能重复:
Fluent Security-配置参数化控制器动作

我正在尝试Fluent Security来在ASP.NET MVC应用程序中强制执行安全策略,但我无法为接受参数的控制器方法定义策略。作为我的意思的一个例子,下面的代码片段显示了应该保护的控制器:

public class AccountController : Controller
{
...
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
return RedirectToAction("Index", "Home");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Disassociate(string provider, string providerUserId)
{
return View();
}
}

而且,这个代码片段(从概念上)展示了我如何尝试配置Fluent Security,以允许对两个控制器方法进行身份验证访问。

SecurityConfigurator.Configure(config => {
config.For<AccountController>().DenyAuthenticatedAccess();
config.For<AccountController>(x => x.LogOff()).DenyAnonymousAccess();
config.For<AccountController>(x => x.Disassociate()).DenyAnonymousAccess();
});

但是,由于没有Disassociate的参数,因此不会生成后一个代码。编译器报告以下内容:No overload for method 'Disassociate' takes 0 arguments

如何为方法AccountController.Disassociate(string, string)配置Fluent Security?

看起来你可以传递任何期望类型的值,所以在我的情况下,我可以做以下事情来安抚编译器:

config.For<AccountController>(x => x.Disassociate("", "")).DenyAnonymousAccess();

最新更新