Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: AuthorizeFilter dysfunction under async implementation [572]

$
0
0
Implement AuthorizeFilter as following:

public class TheAuthrizeAttribute : AuthorizationFilterAttribute
{
public async override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var db = new MockDB();
bool pass = await db.AsyncValidate(actionContext.Request);

// validate;
if (!pass)
{
actionContext.Response = new System.Net.Http.HttpResponseMessage(HttpStatusCode.Unauthorized);
}
}
}

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.
Comments: Ah, sorry. I didn't notice that you are a project member. I thought u were just running into issues and found this place to ask questions :) Back to topic: I think you are right at some point but the developer, who especially writes async code with await, should be aware of the fact that any async method which returns void cannot be awaited by the caller. So, the continuation inside the void-returning async method will be sort of fire and forget unless you employ some sort of state.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>