2010-11-26 72 views
3

我在ASP.NET MVC中设计了一个应用程序,通常保护动作的方法是通过保护整个动作的属性AuthorizeASP.NET MVC的动态安全性

[Authorize(Roles = "Managers")] 
public AtionResult Info(int employeeId) 

但是,在我们的设计中,应用程序是高度数据驱动的。可能允许对一组数据执行操作,而对另一组数据则不允许。

 
//OK 
http://host/Employee/Info/102 

//Not OK 
http://host/Employee/Info/105 

我们应该为这种设计安全使用什么模式?

回答

0

您可以使用派生自ActionFilterAttribute类的自定义属性来修饰您的动作方法,并在OnActionExecuting方法中检查传入请求中的数据,如果不允许,则抛出安全异常/重定向/做任何您需要的操作。

4

您可以创建派生的授权属性来执行任何您想要的操作。

public class DynamicSecurity : AuthorizeAttribute 
{ 
    protected override bool AuthorizeCore(HttpContextBase httpContext) 
    { 
     //go to db 
     return true; 
    } 
}