In our asp.net mvc/web api project, we want to customize the authorization using AuthorizeAttribute
. We have noticed that there are two different AuthorizeAtt
Just extend your IPrincipal
.
public static class IPrincipalExtension
{
public static bool IsValid(this IPrincipal p)
{
// your custom validation
return true;
}
}
Now reference your namespace and use like this.
public class MyAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
{
protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var valid = actionContext.RequestContext.Principal.IsValid(); // this will return boolean
// your code here
}
}