代码之家  ›  专栏  ›  技术社区  ›  C. Ross trotttrotttrott

ASP.NET MVC的动态安全性

  •  3
  • C. Ross trotttrotttrott  · 技术社区  · 14 年前

    我正在用ASP.NET MVC设计一个应用程序,通常保护操作的方法是通过属性 Authorize

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

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

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

    我们应该使用什么模式来保证这个设计的安全性?

    2 回复  |  直到 14 年前
        1
  •  4
  •   John Farrell    14 年前

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

    public class DynamicSecurity : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            //go to db
            return true;
        }
    }
    
        2
  •  0
  •   Lee D    14 年前

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