配置的WebAPI控制器请求超时 [英] Configure request timeout for WebApi controllers

查看:731
本文介绍了配置的WebAPI控制器请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的WebAPI控制器的异步方法:

I'm using async methods in my WebAPi controllers:

public async Task<HttpResponseMessage> SampleMethod(int subscriptionNumber, DateTime departureDate)
{
    // [...]
}

如何配置的请求超时?该操作可能需要长达几分钟的时间,我必须确保该请求不超时。

How do I configure the request timeout? The operation can take up to a couple of minutes and I have to make sure that the request do not timeout.

在MVC有一个名为 [AsyncTimeout] 。是否有一个的WebAPI等同? ?可它在全球范围内配置

In MVC there is an attribute called [AsyncTimeout]. Are there an equivalent in WebApi? Can it be configured globally?

推荐答案

好问题,我建议从客户端处理这个问题 - 你总是可以指定超时设置在消费者的代码,即使是阿贾克斯:

Good question, I would recommend to handle this from client side - you can always specify timeout settings in your consumer code, even if it is ajax:

$.ajax({
url: "/ajax_json_echo/",
timeout: 1000,
...

这篇关于配置的WebAPI控制器请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆