Authorized MVC attribute prohibits

I use the Authorize() attribute to protect my controllers / actions and I want to show only the login action for unauthenticated users - in other words, deny access to authenticated users.

I could not find anything on the Internet regarding denial of permission or permission of negative permissions (i.e.! LoggedIn)

Can anyone point me in the right direction?

MVC2, .Net 4

EDIT: To do clairfy, I want something like this:

 Public Class PublicController Inherits ControllerBase <Authorize()> 'Only logged-in users can logout Public Function Logout() as ActionResult Return View() End Function 'Something here to indicate that only NON-authorized users should see this action Public Function Login() as ActionResult Return View() End Function End Class 
+3
source share
1 answer

Could it be that simple:

 public class DenyAttribute : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { return !base.AuthorizeCore(httpContext); } } 
+11
source

Source: https://habr.com/ru/post/924074/


All Articles