Action Filter in WebApi 2

Its been a while I haven’t blogged for sometime. To create an action filter in Web Api 2 and return the response directly you can use the code below

public class StepUpAttribute : ActionFilterAttribute
public IUserFactory CurrentUser { get; set; }

public override void OnActionExecuting(HttpActionContext filterContext)
if (CurrentUser.IsSteppedUp)

// stop request process and return
filterContext.Response = filterContext.Request.CreateResponse(HttpStatusCode.OK,


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s