In this question and answer, I found one way to do ASP.NET MVC asynchronous processing. However, I cannot get it to work.
Basically, the idea is to create a new implementation of IRouteHandler that has only one GetHttpHandler method . The GetHttpHandler method should return an implementation of IHttpAsyncHandler, not just IHttpHandler, because IHttpAsyncHandler has a Begin / EndXXXX API.
public class AsyncMvcRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new AsyncMvcHandler(requestContext);
}
class AsyncMvcHandler : IHttpAsyncHandler, IRequiresSessionState
{
public AsyncMvcHandler(RequestContext context)
{
}
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext httpContext) { throw new NotImplementedException(); }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
throw new NotImplementedException();
}
public void EndProcessRequest(IAsyncResult result)
{
throw new NotImplementedException();
}
}
}
RegisterRoutes Global.asax.cs AsyncMvcRouteHandler. public static void RegisterRoutes ( RouteCollection) { routes.IgnoreRoute( "{}.axd/{* PathInfo}" );
routes.Add(new Route("{controller}/{action}/{id}", new AsyncMvcRouteHandler())
{
Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" }),
});
}
ProcessRequest, BeginProcessRequest EndProcessRequest. ProcessRequest. , AsyncMvcHandler IHttpAsyncHandler. ASP.NET MVC IHttpHandler.
ASP.NET MVC AsyncMvcHandler IHttpAsyncHandler, ?