Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Make ASP.NET MVC Recognize IHttpAsyncHandler from IRouteHandler.GetHttpHandler()?
    primarykey
    data
    text
    <p>In this <a href="https://stackoverflow.com/questions/275545/does-aspnet-mvc-framework-support-asynchronous-page-execution">question &amp; answer</a>, I found one way to make ASP.NET MVC support asynchronous processing. However, I cannot make it work.</p> <p>Basically, the idea is to create a new implementation of IRouteHandler which has only one method <strong><em>GetHttpHandler</em></strong>. The <strong><em>GetHttpHandler</em></strong> method should return a IHttpAsyncHandler implementation instead of just IHttpHandler, because IHttpAsyncHandler has Begin/EndXXXX pattern API.</p> <pre><code>public class AsyncMvcRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { return new AsyncMvcHandler(requestContext); } class AsyncMvcHandler : IHttpAsyncHandler, IRequiresSessionState { public AsyncMvcHandler(RequestContext context) { } // IHttpHandler members public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext httpContext) { throw new NotImplementedException(); } // IHttpAsyncHandler members public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { throw new NotImplementedException(); } public void EndProcessRequest(IAsyncResult result) { throw new NotImplementedException(); } } } </code></pre> <p>Then, in the RegisterRoutes method of file Global.asax.cs, register this class <strong><em>AsyncMvcRouteHandler</em></strong>. public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");</p> <pre><code> routes.Add(new Route("{controller}/{action}/{id}", new AsyncMvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" }), }); } </code></pre> <p>I set breakpoint at <strong><em>ProcessRequest</em></strong>, <strong><em>BeginProcessRequest</em></strong> and <strong><em>EndProcessRequest</em></strong>. Only <strong><em>ProcessRequest</em></strong> is executed. In another word, even though <strong><em>AsyncMvcHandler</em></strong> implements <strong><em>IHttpAsyncHandler</em></strong>. ASP.NET MVC doesn't know that and just handle it as an IHttpHandler implementation.</p> <p>How to make ASP.NET MVC treat <strong><em>AsyncMvcHandler</em></strong> as <strong><em>IHttpAsyncHandler</em></strong> so we can have asynchronous page processing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload