views:

95

answers:

1

I have a list of actions on various controllers that are 'Admin' functions (create, update, delete) but other actions on those same controllers that aren't admin actions.

What I want to do is create a route that will prefix /Admin/ before all urls that call an action that have the Authorize filter attribute.

Is this even possible to do?

A: 

Yes everything is possible, but I think what you mean to say is it easy to do? And the answer is no. What you have to do is create your own route, and then add this customized route to the route mapping. This isn't hard to do, but the problem arises in that the routes are initialized before the controller, so you will have to handle the lookup and reflection yourself to check for your criteria.

There is an alternative option, you can try to use the ActionMethodSelectorAttribute which allows you to create custom selectors for your Action Methods and ignore ones that don't contain the Authorize attribute. An example of this attribute being used is the ActionVerbAttribute.

The easiest way by far is to just create a custom extension for the Html.ActionLink that does its own checks and keep it as a display only thing, and then create dual routes for the same controller in your Global.asax.

Nick Berardi