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
.
To add a generic handler to your website, right-click on the website, choose Add New Item, and choose Generic Handler. Enter a filename and click on the Add button.
The full synchronous handler is shown below. It is simply a class derived from IHttpHandler...