You're tasked with creating a middleware that logs every incoming request's User-Agent header. Which approach would you take to capture this data in ASP.NET Core?

  • Using UseMiddleware extension method
  • Implementing a custom middleware class
  • Utilizing a filter attribute
  • Directly modifying the ASP.NET Core pipeline
To capture the User-Agent header in ASP.NET Core, you would create a custom middleware class that intercepts incoming requests. This middleware class can access the request headers and log the User-Agent information as needed. The UseMiddleware extension method is used to add custom middleware components to the pipeline.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *