Implement AuthorizeFilter as following:<br /><br /> public class TheAuthrizeAttribute : AuthorizationFilterAttribute<br /> {<br /> public async override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)<br /> {<br /> var db = new MockDB();<br /> bool pass = await db.AsyncValidate(actionContext.Request);<br /><br /> // validate;<br /> if (!pass)<br /> {<br /> actionContext.Response = new System.Net.Http.HttpResponseMessage(HttpStatusCode.Unauthorized);<br /> }<br /> }<br /> }<br /><br />The db.AsyncValidate return in 500 ms. However the work flow continues without waiting for its return and the Action with this AuthorizeAttribute ultimately been executed.
↧