Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use async/await in MVC 4 AuthorizeAttribute?

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?

like image 203
Evan Avatar asked May 15 '14 22:05

Evan


People also ask

Should I use async await everywhere C#?

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.

Does async await use thread pool?

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.

What happens if we dont use async await?

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.


1 Answers

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.

like image 161
Stephen Cleary Avatar answered Sep 22 '22 04:09

Stephen Cleary