Asynchronous generic handlers

When you use AJAX-type asynchronous requests from your page to retrieve data from the database, you would want to use an .ashx generic handler or maybe a web service to process that request, rather than a full-blooded .aspx page. This will save you the overhead of the full page life cycle.

Accessing a database asynchronously from a generic handler is different from doing the same from a page. Let's see how this works.

Synchronous version

Firstly, let's have a quick look at a synchronous generic handler. We'll then work that into its asynchronous counterpart using the asynchronous data access layer we just saw.

You'll find the code in the downloaded code bundle in the folder ThreadStarvation_Db_Sync, file Handler.ashx ...

Get ASP.NET Site Performance Secrets now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.