In .NET core 6 API application. I would like to cancel the incoming request if it's take more than x minutes to complete the call in service layer and return with 504 status code. In my service layer all i have is regular async method that make a call to active directory lookup.
I am using IIS to host this API. I have try settings in IIS itself but no luck.
There is attribute called requestTimeout in web.config but it doesn't work with in-process hosting.
You can configure an endpoint to timeout by calling WithRequestTimeout, or by applying the [RequestTimeout] attribute
For apps with controllers, apply the
[RequestTimeout]attribute to the action method or the controller class. For Razor Pages apps, apply the attribute to the Razor page class.https://learn.microsoft.com/en-us/aspnet/core/performance/timeouts?view=aspnetcore-8.0&viewFallbackFrom=aspnetcore-6.0