Task async controller method does not hit
asp.net-mvc, asp.net-mvc-routing, async-await, c#, routes
Solution
I believe that your example will work if you derive your Controller from AsyncController instead.
public class MyController:AsyncController
{
public async Task<ActionResult> IndexAsync()
{
return View(); //view called "Index.cshtml", not "IndexAsync.cshtml"
}
}
So now you can hit `~/My/Index` without the `Async` suffix, despite `Async` appearing in the controller name.
This is a relic from the previous MVC asynchronous controller method, and usually required an `IndexComplete` method to work, but with Task based async controller method, the matching `XxxxComplete` method is not required, but the `Async` convention is observed.
The actual implementation of `AsyncController` is rather sparse:
public abstract class AsyncController : Controller
{
}
So somewhere in the MVC stack, the type of the controller is tested, and special routing magic is turned on.
Problem
So, we've got an MVC project that has been upgraded through the different versions of MVC from 1 through to 4. Now we have a controller method: ``` public async Task<ActionResult> IndexAsync() ``` so if we go to `http://somedomain.xyz/WhicheverController` or `http://somedomain.xyz/WhicheverController/Index`, we are greeted with a 404. `http://somedomain.xyz/WhicheverController/IndexAsync` routes to the method just fine. What's gone wrong with our routing?