views:

41

answers:

1

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.

From my Intercept method I need access to the action that is called. I figured out how to get the controller and action names (through the RequestContext), but not the actual method - any good ideas?

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

invocation.Method gives you the intercepted method, but I think you'd be better of using an ActionFilter instead.

Mauricio Scheffer