One of the filters on an application I'm developing checks to see if a user owns the item they are trying to alter. The action is decorated by the [RequiresOwnership]
attribute, and inside the attribute logic, I check to see if the user owns the item, and if they don't, I throw an UnauthorizedAccessException
.
My question is this: Where can I catch that exception? I would ideally like to redirect the user to a page explaining why what they tried to do wasn't allowed, instead of just showing an exception page. I don't think I would be catching the exception inside the action that is decorated by the attribute, so is there some base part of the application where I can handle exceptions thrown higher up, in the .NET MVC model?
EDIT: I realize that I could just redirect to a page via the filter itself, but that seems a little hacky to me. It would be nice to throw exceptions via attributes, and have one standard place where they can be caught and dealt with.