技术
我在我的应用程序中使用了 angular 2 和 Web API 技术。我正在通过 $http 调用从 angular 调用 Web API 服务方法。
我在做什么
实际上API方法是从数据库中读取数据并做巨大的为 UI 实体类转换数据的逻辑(那里有很多代码和循环,所以我不会在这里发布它们)。
问题和根本原因是什么
问题是我在调用 API 方法时收到 502 Bad get way 错误。
我发现了这个问题,因为它是一个性能问题。当数据量很小时,它对我来说很好用。但是如果数据量很大,那么我就会收到这个错误。
注意:我已经检查了数据库查询。它工作正常并且返回数据非常快。
性能结果详情
我已经使用计时器来检查 API 方法的响应时间
Result of response time as follow :
我的理解:
如果方法响应时间超过 2 分钟,那么只有我遇到了错误的获取方式错误。否则方法成功执行,没有任何错误。
我试图修复这个错误:
我试过增加
executionTimeout=9000
在 web config.
我也在 executionTimeout.
中尝试了不同的秒数这是我的完整网络配置代码
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.web>
<authentication mode="Windows"></authentication>
<authorization>
<deny users="?" />
</authorization>
<httpRuntime executionTimeout = "9000" />
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true" />
</system.webServer>
</configuration>
but still i am unable to solve this problem. Could you please let me know how can I fix this issue?
最佳答案
我通过添加 requestTimeout="00:10:00"
解决了这个缺陷在 <aspNetCore/>
部分
<aspNetCore processPath="%LAUNCHER_PATH%" requestTimeout="00:10:00"
arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="true" />
关于c# - 大数据量的 Web API 中的 502 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51894782/