I’m using the Authorize attribute to filter controller actions based on user roles, but if an unauthorized action is attempted, the user is redirected back to the login page. As I user I would find this confusing and irritating.
How can I instead show an error message informing the user they need certain roles, and remain on the view where they attempted an action?
You will need to write a custom
Authorizeattribute which doesn’t return aHttpUnauthorizedResult. Also remaining on the same view will be a difficult task as you might need to keep all the context after the request.