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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.