locked
Implementing/using ASP.NET IHttpAsyncHandler RRS feed

  • Question

  • I see that ASP.NET WebForm pages can be made Async and used with the async CTP's async modifier.

    I'd love love to know how to implement an async handler using the async CTP. I've looked at this (sort of related) post but can't seem to figure out how one should implement this.

    Has anyone done this or know how?


    http://www.matlus.com
    • Edited by Shiv Kumar Wednesday, November 16, 2011 12:44 PM
    Wednesday, November 16, 2011 12:42 PM

Answers

  • Hi Shiv-

    The IHttpAsyncHandler interface is based on the APM pattern, requiring you to implement BeginProcessRequest and EndProcessRequest methods.  Thus, all you really need is a way to take your Task-returning method (e.g. a Task-returning method you implement named ProcessRequestAsync) and wrap it in an APM implementation.  The blog post at http://blogs.msdn.com/b/pfxteam/archive/2011/06/27/10179452.aspx describes how to do that.

    Note that ASP.NET in .NET 4.5 provides the HttpTaskAsyncHandler type, which does that for you, providing an abstract Task-returning ProcessRequestAsync method for you to implement. 

    I hope that helps.

    Friday, November 18, 2011 4:15 PM
    Moderator

All replies

  • Hi Shiv-

    The IHttpAsyncHandler interface is based on the APM pattern, requiring you to implement BeginProcessRequest and EndProcessRequest methods.  Thus, all you really need is a way to take your Task-returning method (e.g. a Task-returning method you implement named ProcessRequestAsync) and wrap it in an APM implementation.  The blog post at http://blogs.msdn.com/b/pfxteam/archive/2011/06/27/10179452.aspx describes how to do that.

    Note that ASP.NET in .NET 4.5 provides the HttpTaskAsyncHandler type, which does that for you, providing an abstract Task-returning ProcessRequestAsync method for you to implement. 

    I hope that helps.

    Friday, November 18, 2011 4:15 PM
    Moderator
  • Hi Stephen,

    Thanks for your reply and the link to your blog post. Can't imagine why I missed it since I've been all over your blog.

     

    I saw (before posting here) that ASP.NET 4.5 does provide such a capability out of the box but I'm not sure if we can use .NET 4.5 in production.

    I'm modifying a product I'm currently working on to use the TAP with the async CTP to be deployed in Azure.

    Being able to use ASP.NET 4.5 will just make it easier.


    http://www.matlus.com
    Friday, November 18, 2011 5:35 PM
  • Hi Stephen,

    There seem to be some issue using your ToAPM() method from within a handler. Essentially, it just hangs. Probably something to do with synchronization context?

    I haven't gotten to the bottom of it yet (had to move on to something else) but thought I'd give you a heads up and hoping you'd know what the issue might be off of the top of your head.


    http://www.matlus.com
    Saturday, November 19, 2011 8:15 PM