I’d like [Authorize] to redirect to loginUrl unless I’m also using a role, such as [Authorize (Roles="Admin")]. In that case, I want to simply display a page saying the user isn’t authorized.
What should I do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is the code from my modified implementation of
AuthorizeAttribute; I named itSecurityAttribute. The only thing that I have changed is theOnAuthorizationmethod, and I added an additional string property for the Url to redirect to an Unauthorized page:You call it the same way as the original
AuthorizeAttribute, except that there is an additional property to override the Unauthorized Page Url: