【问题标题】:How to return 504 (gatewayTimeout) in WebApi如何在 Web Api 中返回 504(网关超时)
【发布时间】:2015-08-26 10:19:38
【问题描述】:

在我的公司 API(我们使用 WebAPI 2)中,当控制器操作需要很长时间时,我们希望返回 504(网关超时)。有时在我们的 WebAPI 操作中,我们会与外部公司 API 合作,这些 API 并不总是能正常工作,因此对用户来说可能很方便。

我在 web.config 中添加了条目,但它不起作用。

<system.transactions>
    <defaultSettings timeout="00:00:10" />
</system.transactions>

我该如何解决这个问题?

【问题讨论】:

    标签: c# .net api http asp.net-web-api


    【解决方案1】:

    超时设置为秒数,我认为您应该使用 httpruntime executiontimeout 而不是事务超时,它只会影响请求中的事务

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

    【讨论】:

    • 它不工作。我阅读了有关 thois 设置的信息,还需要在编译节点中将 debug 设置为 false。但它仍然无法正常工作
    • 您是在服务器 iis 上运行,还是在 Visual Studio 中与内置服务器的调试会话上运行?
    • 我使用 Visual Studio IIS Express
    猜你喜欢
    • 2021-10-28
    • 1970-01-01
    • 2018-09-20
    • 2013-05-20
    • 1970-01-01
    • 2017-02-05
    • 2017-11-21
    • 1970-01-01
    相关资源
    最近更新 更多