Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何限制(同步).net WebApi请求的执行/请求时间?_C#_.net_Iis_Asp.net Web Api - Fatal编程技术网

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

C# 如何限制(同步).net WebApi请求的执行/请求时间?,c#,.net,iis,asp.net-web-api,C#,.net,Iis,Asp.net Web Api,我有一个.net MVC应用程序,其中包含一些控制器和一些APIController APIController最近才上线,在IIS中查找一些请求似乎无休止地继续(非WebApi的请求很好)。 这会导致服务器上的CPU最大化 我意识到我需要解决他们运行时间太长的问题,但如果他们这么做了,我希望他们暂停,我不知道如何实现这一点 服务器作为AWS负载平衡器后面的AWS Windows实例。负载平衡器有30秒的空闲超时 我已经将IISexecutionTimeout配置为30秒(我不清楚这是否会限制同

我有一个.net MVC应用程序,其中包含一些
控制器和一些
APIController

APIController最近才上线,在IIS中查找一些请求似乎无休止地继续(非WebApi的请求很好)。 这会导致服务器上的CPU最大化

我意识到我需要解决他们运行时间太长的问题,但如果他们这么做了,我希望他们暂停,我不知道如何实现这一点

服务器作为AWS负载平衡器后面的AWS Windows实例。负载平衡器有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);
}
...

了解如何在C#和.NET中使用任务并行库。然后,您可以使用自己的代码轻松添加超时检查。谢谢。我想按照你的建议做,但现在我只是在寻找一个配置。或者理解为什么我的尝试没有成功。