如何限制(同步).net WebApi请求的执行/请求时间?

时间:2018-06-08 10:39:36

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

我有一个.net MVC应用程序,其中包含一些Controllers和一些ApiControllers

ApiControllers最近刚刚上线,在IIS中看到一些请求似乎无休止地继续(非WebApi就好了)。 这导致CPU在服务器上最大化。

我意识到我需要解决他们运行这么长时间的问题,但是如果他们这样做的话,我希望他们能够暂停,而且我无法解决如何实现这一目标。

作为AWS Windows实例的服务器位于AWS负载均衡器后面。负载均衡器有30秒的空闲超时。

我已将IIS executionTimeout配置为30秒(我不清楚这是否会限制同步WebApi请求,但似乎没有。)

我的问题是如何限制WebApi请求的执行/请求时间?

作为参考,这是一个示例端点:

public class ProfileController : ApiController
{

[HttpPost]
[Route("~/api/profile/delete/{entryId}")]
public ApiResult Delete(int entryId)
{
    var sharedContent = _sharedContentRepository.Get(entryId);

    if (sharedContent == null)
    {
        var response = new ApiResult(false, "Shared Content not found");
        return response;
    }

    var currentUser = _userService.CurrentUser();

    if (currentUser == null || currentUser.Id != sharedContent.SharedBy.Id)
    {
        return new ApiResult(false, "Not user's shared content to delete");
    }

    sharedContent.Hidden = true;

    return new ApiResult(true);
}
...

0 个答案:

没有答案
相关问题