helloworld
helloworld

Reputation: 2311

Intercept controller request with Authorize attribute

How can I intercept requests to a controller and check if the controller called has an [Authorize] attribute set? And if controller has it, How can override default implementation with my custom authentication routine?

thanks

Upvotes: 1

Views: 387

Answers (1)

archil
archil

Reputation: 39501

public class MyAuthorizeAttribute : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
         //your authorization logic here
    }
}

And use [MyAuthorizeAttribute] instead of [Authorize] on your controllers or actions

Upvotes: 3

Related Questions