ASP.NET offers 4 types of http handlers – synchronous, asynchronous, generic synchronous (ashx) and generic asynchronous (ashx) handlers.
How do you choose the type of http handler to use for a job?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are no hard-and-fast rules, but here are a few guidelines for you:
sync vs. async: use sync when you don’t have any long-running tasks. Use async when you do. For example, if the handler queries a database or makes a web service call, then it should be async.
generic vs. custom: use generic if you don’t care about the extension in the URL (it will be *.ashx). Use custom if the extension is important (perhaps to generate custom PNG images). Full-custom handlers require an extra step to register them in web.config, but are otherwise pretty much identical to generic handlers.
Also, it may help to keep in mind that the Page class is really just an HttpHandler that happens to handle .aspx files — and you can of course have sync and async pages, too, with the same guidelines as above.
In case it’s of interest, I cover this info in detail in my book, including examples (Ultra-Fast ASP.NET).