I need to increase the request timeout for a specific controller action in my application programmatically in the controller.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
The best way I have found so far to handle a long running script (if your application simply can't avoid having one) is to firstly create an async handler:
In the snippet above I have added a Cancellation token to say that my Async Method should cancel after 180 seconds (even though in this example it will never delay for longer than 150 seconds) I've added the timeout to ensure there is a cap on how long my script can run.
If you run this you will get a HTTP Error 502.3 since there is a timeout set on the httpPlatform of 00:02:00.
To extend this timeout go to the web.config file inside the wwwroot folder and add a requestTimeout="00:05:00" property to the httpPlatform element. For Example:
The long running script should now work.
This does, however, mean that any request will take 5 minutes to timeout so you will have to ensure that you use the CancellationToken trick to limit any Async requests you have in your application. In previous versions of MVC we had the AsyncTimeOut attribute that you could add to a controller, but it appears that this has been cut in MVC6 See GitHub aspnet/mvc Issue #2044