Return HTML Response Directly from Azure Functions (.NET)

In case you want to send HTML content as HTTP response directly from Azure Functions (in .NET), you can use following code snippet to reduce your work. 

.NET Core 3.1 and lower

Following code is designed for Azure Functions running on .NET Core 3.1 (or lower). Just create a file HtmlObjectResult.cs and return new class instance as result of your Azure Function.

What about .NET 5

In .NET 5 a guide above will not work. In fact, in .NET 5 (Azure Functions in isolated process) you don’t need any custom code, a Function has during runtime easy access to HttpRequestData object, so you can easily create a response like this:

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna.