代码之家  ›  专栏  ›  技术社区  ›  Christian Nielsen

通过温莎II接口进行操作访问

  •  0
  • Christian Nielsen  · 技术社区  · 17 年前

    我希望通过使用Windsor II interceptor来处理MVC应用程序中的授权,因为这似乎是我唯一可以获得对传递操作的参数的命名访问权限的方法,这些参数与确定用户是否有访问权限有关。

    我需要通过Intercept方法访问所调用的操作。 我弄清楚了如何获取控制器和动作名称(通过RequestContext),但没有找到实际的方法——有什么好主意吗?

    作为参考,这大致是代码的样子:

    public class AuthorizationInterceptor : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            if (invocation.Arguments != null && invocation.Arguments.Length > 0 && invocation.Arguments[0] != null)
            {
                if (invocation.Arguments[0].GetType() == typeof(RequestContext))
                {
                    var context = (RequestContext)invocation.Arguments[0];
                    var values = context.RouteData.Values;
    
                    if (!auth.Authorize(values, HttpContext.Current.User))
                    {
                        //RedirectToLogin                    }
                }
            }
    
            invocation.Proceed();
        }
    }
    
    1 回复  |  直到 17 年前
        1
  •  0
  •   Mauricio Scheffer    17 年前

    invocation.Method 给你截取的方法,但我认为你最好使用 ActionFilter 相反。