The only override I see exposed on MVC's AuthorizeAttribute
is public override void OnAuthorization( AuthorizationContext filterContext )
which is not suitable for use with async/await because it doesn't return a Task
. Is there another way to create an AuthorizeAttribute
in MVC that allows the use of async/await?
Async/Await has been around since C# version 5.0 (2012) and has quickly become one of the pillars of modern . NET programming — any C# developer worth his/her salt should be using it to improve application performance, overall responsiveness, and code legibility.
The async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active.
The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting for the task to complete. In most cases, that behavior isn't expected.
ASP.NET MVC today does not support asynchronous filters. Please vote.
However, ASP.NET "vNext", announced at TechEd this week, will support asynchronous filters for MVC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With