I use a custom authorization filter on my ASP.NET MVC controllers, which redirects the user to a URL other than the login screen if they are not authorized for a specific action.
This is fine for actions that return views, but many of my actions return other types of results, such as PartialResult or JsonResult.
My current filter is as follows:
<AuthorizeWithRedirect (Roles: = "ServerAccess", Controller: = "Home", Action: = "Unauthorized")>
This means that if the user is not in the ServerAccess role, they should be redirected to / Home / Unauthorized /
I'm curious how other people handle this? This seems especially problematic if you are considering the number of actions that are intended to be invoked only on the client side by an AJAX script. How can / Home / Unauthorized / action know if the caller should receive a view, partial view, json, content, etc.
Nick source
share