简体   繁体   English

通过Windsor IInterceptor进行操作访问

[英]Action access through Windsor IInterceptor

Im looking to handle authorization in an MVC app through the use of a Windsor IInterceptor - because this seems like the only way I can get named access to parameters the action is passed which are relevant for determining if the user has access. 我希望通过使用Windsor IInterceptor在MVC应用程序中处理授权-因为这似乎是我可以对操作传递的参数进行命名访问的唯一途径,该操作与确定用户是否具有访问权限有关。

From my Intercept method I need access to the action that is called. 从我的Intercept方法中,我需要访问被调用的动作。 I figured out how to get the controller and action names (through the RequestContext), but not the actual method - any good ideas? 我想出了如何(通过RequestContext)获得控制器和动作的名称,而不是实际的方法-有什么好主意吗?

As a reference this is roughly how the code looks as is: 作为参考,代码大致如下所示:

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();
    }
}

invocation.Method为您提供了被拦截的方法,但是我认为您最好使用ActionFilter代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM