gpt4 book ai didi

asp.net - 长时间 ASP.NET 操作时 IIS 请求超时

转载 作者:行者123 更新时间:2023-12-03 05:11:03 26 4
gpt4 key购买 nike

当我运行长时间操作时,我遇到来自 IIS 的请求超时。我的 ASP.NET 应用程序正在后台处理数据,但处理的记录数量很大,因此操作需要很长时间。

但是,我认为 IIS 使 session 超时。这是 IIS 或 ASP.NET session 的问题吗?

最佳答案

如果您想延长 ASP.NET 脚本执行的时间,请增加 Server.ScriptTimeout值(value)。 .NET 1.x 的默认值为 90 秒,.NET 2.0 及更高版本的默认值为 110 秒。

例如:

// Increase script timeout for current page to five minutes
Server.ScriptTimeout = 300;

此值也可以在 httpRuntime 中的 web.config 文件中配置。配置元素:

<!-- Increase script timeout to five minutes -->
<httpRuntime executionTimeout="300"
... other configuration attributes ...
/>

enter image description here

请按照MSDN documentation备注:

"This time-out applies only if the debug attribute in the compilation element is False. Therefore, if the debug attribute is True, you do not have to set this attribute to a large value in order to avoid application shutdown while you are debugging."

如果您已经执行此操作,但发现您的 session 即将过期,请增加ASP.NET HttpSessionState.Timeout值:

例如:

// Increase session timeout to thirty minutes
Session.Timeout = 30;

此值也可以在 web.config 文件的 sessionState 配置元素中配置:

<configuration>
<system.web>
<sessionState
mode="InProc"
cookieless="true"
timeout="30" />
</system.web>
</configuration>

如果您的脚本需要几分钟才能执行,并且有许多并发用户,请考虑将页面更改为 Asynchronous Page 。这将提高应用程序的可扩展性。

如果您具有服务器的管理员访问权限,则另一种选择是将此长时间运行的操作视为作为计划任务或 Windows 服务实现的候选者。

关于asp.net - 长时间 ASP.NET 操作时 IIS 请求超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3829202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com