How do I set the request timeout for one controller action in an asp.net mvc application

后端 未结 3 963
执笔经年
执笔经年 2020-11-30 20:47

I want to increase the request timeout for a specific controller action in my application. I know I can do it in the web.config for the entire application, but I\'d rather c

相关标签:
3条回答
  • 2020-11-30 21:16

    You can set this programmatically in the controller:-

    HttpContext.Current.Server.ScriptTimeout = 300;
    

    Sets the timeout to 5 minutes instead of the default 110 seconds (what an odd default?)

    0 讨论(0)
  • 2020-11-30 21:18
    <location path="ControllerName/ActionName">
        <system.web>
            <httpRuntime executionTimeout="1000"/>
        </system.web>
    </location>
    

    Probably it is better to set such values in web.config instead of controller. Hardcoding of configurable options is considered harmful.

    0 讨论(0)
  • 2020-11-30 21:18

    I had to add "Current" using .NET 4.5:

    HttpContext.Current.Server.ScriptTimeout = 300;
    
    0 讨论(0)
提交回复
热议问题