【发布时间】:2011-03-07 17:24:26
【问题描述】:
是否可以增加单个 ASP.net 页面的超时时间。我知道在服务器级别可以,但是在页面级别可以吗?
我需要这个用于加载需要 2-3 分钟的单个报告页面
有什么想法吗?
【问题讨论】:
-
增加超时时间?你的意思是减少吗?要增加页面加载时间,您始终可以使用 Thread.Sleep (msdn.microsoft.com/en-us/library/d00bd51t.aspx)。
是否可以增加单个 ASP.net 页面的超时时间。我知道在服务器级别可以,但是在页面级别可以吗?
我需要这个用于加载需要 2-3 分钟的单个报告页面
有什么想法吗?
【问题讨论】:
我认为您正在寻找的是ScriptTimeout。您可以像这样设置此页内:
Page.Server.ScriptTimeout = 60;
超时值以秒为单位。
另外,请注意,如果您在调试模式下运行,这将被忽略并且超时设置为最大值;不过,我认为这对您来说不是问题,因为您正在增加超时,而不是减少它。
根据this page,我也可以验证,实现此目的的另一个好方法是将其添加到您的配置的configSection:
<location path="~/MyPage.aspx">
<system.web>
<httpRuntime executionTimeout="600"/>
</system.web>
</location>
您还可以添加其他属性,例如 maxRequestLength="204800" 或其他部分,例如:
<location path="~/MyPage.aspx">
<system.web>
<httpRuntime executionTimeout="6000" maxRequestLength="204800" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" />
</requestFiltering>
</security>
</system.webServer>
</location>
希望这会有所帮助。
【讨论】:
我发现我的问题已通过增加 SQL 超时得到解决,
使用command.CommandTimeout = 100;
示例:
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = new SqlCommand(queryString, connection);
// Setting command timeout to 100 seconds
command.CommandTimeout = 100;
command.ExecuteNonQuery();
}
【讨论】: