0

I am looking to use middle ware to decrypt the http request coming to azure function in start up.cs class. below is my start up class

public class Startup : FunctionsStartup { public override void Configure(IFunctionsHostBuilder builder) { if (builder == null) throw new ArgumentNullException(null, new Exception()); ConfigureServices(builder.Services).BuildServiceProvider(true); }

IFunctionsHostBuilder does not contain any method like builder.UseMiddleware? So not getting idea how to do that. can somebody help

1 Answers1

0

How to use Middle Ware in Azure Function in start up class

Firstly Azure Functions won't have startup class by default, But Services can be added using IWebJobStartup and secondly you cannot add custom middleware in startup class. Rather you can create your own middleware function by implementing IHttpMiddleware or sub-class HttpMiddleware

public class UtcRequestDateMiddleWare : HttpMiddleware
{
    public override Task InvokeAsync(HttpContext context)
    {
       context.Response.Headers["x-request-date-utc"] = System.DateTime.UtcNow.ToString("o");
    }
}

check the SO for further reference

Find how to create Middleware Functions

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15