You can refer to this article for solution using middleware.
https://www.seeleycoder.com/blog/asp-net-core-request-timeout-iis-in-process-mode/
https://github.com/fooberichu150/request-timeout
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In my asp.net core 5.0 app, I call an async method that might take some time to be processed.
await someObject.LongRunningProcess(cancelationToken);
However, I want that method to be timeout after 5 seconds. I know that instead of "cancelationToken" passed by asp.net core action, I can use "CancellationTokenSource" :
var s_cts = new CancellationTokenSource();
s_cts.CancelAfter(TimeSpan.FromSeconds(5);
await someObject.LongRunningProcess(s_cts );
Is it possible to use "CancellationTokenSource" as a default "Cancelation Token" policy for all asp.net core requests ? I mean override the one which is passed as a parameter of the action ?
Or is it possible to change the default timeout for all request in asp.net core 5.0 ?
You can refer to this article for solution using middleware.
https://www.seeleycoder.com/blog/asp-net-core-request-timeout-iis-in-process-mode/
https://github.com/fooberichu150/request-timeout
note: while you can set the cancellation token in middleware, all your actions still need to pass it to any async tasks they call. also be sure the tasks honor the cancellation token.