This video introduces HTTP handlers and their role in the request processing pipeline, as well as common scenarios for creating custom handlers.
- An HTTP handler is the process, also called the endpoint, that runs in response to a request. It's used to handle specific requests based on file extensions and verbs. You can leverage these handlers to inject processing logic into the request pipeline. When a request comes in from a client, the ASP.NET runtime assigns the appropriate handler to it. The assignment is based on the file extension and verb of the request URL.
Keep in mind that only one handler processes the request. There's built in ASP.NET handlers like the page handler that processes ASPX files, and a VC handler, which initiates the ASP.NET pipeline for an MVC application. You can also create your own custom HTTP handler to render a response to the browser. Let's look at some common situations where you'd create a custom handler.
Ask yourself if you have a requirement to serve requests to a specific URL or extension. For instance, if your website serves image files, you can write a custom handler to resize them before they're sent back in the response. Another scenario might be to create an RSS feed. A custom handler could respond to requests with an RSS extension and return RSS formatted XML.
Handlers can be synchronous or asynchronous. With a synchronous handler a response isn't returned back until it's done processing the HTTP request. Because of its synchronous nature, you would use it to run shorter processes. On the other hand, an asynchronous handler processes the request on another thread, and the client doesn't have to wait to get a response. This would be a good choice for lengthy or external processes, like connecting to a remote server.
It can help improve performance and prevent situations where your handlers blocked while it waits on a long running task. We'll look at how implement both types of handlers next.
- Fundamentals of the request life cycle
- Designing and implementing HTTP modules and handlers
- Choosing between handlers and modules
- Understanding route handlers
- Configuring convention-based routing
- ASP.NET MVC attribute routing
- Creating a custom controller factory
- Defining a custom dependency resolver
- Creating a custom view engine