11

我已经实现了一个 ASP.NET http 处理程序。在我看来,没有办法设置超时,例如,如果处理程序已经运行超过 X 秒,则不提供结果。

我在这里是正确的还是有办法为 ashx 处理程序实现超时?

4

1 回答 1

19

ASP.Net 有一个内置超时,这将导致它终止超过配置限制的连接。

默认值为 110 秒。

<system.web>
    <httpRuntime executionTimeout="110">        
</system.web>

但是,在 DEBUG 模式下编译时会禁用此功能。

<!-- Execution Timeout Will Not Be Enforced -->
<compilation debug="true" />

如果您需要为特定处理程序设置执行超时,那么您始终可以专门为该处理程序创建一个位置,并在那里设置超时。

<location path="MyHandler.ashx">
  <system.web>
    <!-- Set execution timeout to 10 minutes -->
    <httpRuntime executionTimeout="600"/>
  </system.web>
</location>
于 2012-04-27T16:25:53.410 回答