Popular Use Cases for Message Handlers | C#

In this chapter, we consider examples of how to create custom Message Handlers to implement a custom schema, work with HTML documents from a ZIP archive, authentication, and log an operation time.

A typical implementation does the following:

  1. To write a custom message handler, derive from Aspose.Net.MessageHandler and override the Invoke() method.
  2. Add the custom message handler in the pipeline.

Suppose you want to convert an HTML(XHTML) document containing linked resources such as images, styles, scripts. In that case, you should pack all these resources along with your document into a single ZIP archive and convert, for instance, ZIP to PDF or ZIP to JPG. Aspose.HTML for .NET provides functionality for creating custom message handlers for working with HTML documents in ZIP archives.

Sometimes you need to get the total time taken for a Web request to flow through handlers, out to the endpoint, and receive the response. So, another popular use case for message handlers – logging the Web request execution time.

Convert HTML from ZIP archive to PDF – In the article, you will find a message handler implementation for working with ZIP archives and an example of converting HTML from ZIP archive to PDF.

Convert HTML from ZIP archive to JPG – This article provides an example of implementing a message handler for converting HTML from ZIP archive to JPG using Aspose.HTML for .NET.

Web Request Execution Time – This article will consider an example of implementing a message handler for logging a Web request execution time.

Network Timeouts – In this article, we will discuss how to set network timeouts in C# with practical examples.

Check Network Requests – This article considers examples of intercepting requests, blocking some unwanted external network requests, or replacing the URLs with some other value.

Execution Time Logging – In this article, you will find an example of custom message handlers to convert HTML from ZIP archive to PDF and log the execution time of this conversion.

Authentication – In this article, you find a simple example of how to create a custom message handler for a Web request with password-based authentication schemes such as basic, digest, NTLM, and Kerberos.

Aspose.HTML offers online Converters for converting HTML, XHTML, MHTML, XML, EPUB, and Markdown files to various popular formats. Just select a file, choose a format to convert, and you’re done. It’s fast and completely free!

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.