源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

ASP.NET页面请求超时时间设置多种方法

  • 时间:2022-10-04 01:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:ASP.NET页面请求超时时间设置多种方法
[img]http://files.jb51.net/file_images/article/201609/201609280917341.png[/img] ASP.NET [b]页面请求超时时间(页面后台程序执行时间)默认值为110秒[/b](在 .NET Framework 1.0 版和 1.1 版中,默认值为 90 秒) 即: [b]Server.ScriptTimeout = 110[/b](HttpServerUtility.ScriptTimeout = 110) [b]System.Web.Configuration.HttpRuntimeSection().ExecutionTimeout.ToString() =00:01:50[/b](110 秒) [b]方法一:[/b]设置 Server.ScriptTimeout 的值 注意:设置的值必须大于90,否则不会生效,请求超时值依然是90秒 (网上流传的说法,经验证错误!!!) 只有当compilation元素中的调试属性为False时,此超时属性才适用(true:ScriptTimeOut=30000000)。若要避免在调试期间关闭应用程序,请不要将此超时属性设置为较大值。 <span style="font-family: 'Microsoft YaHei';">//单位秒 Server.ScriptTimeout = 60;</span> [b]方法二:[/b]Web.config 配置httpRuntime executionTimeout (单位秒) 注意:只有当compilation元素中的调试属性为False时,此超时属性才适用(true:ScriptTimeOut=30000000)。若要避免在调试期间关闭应用程序,请不要将此超时属性设置为较大值。 [b]httpRuntime executionTimeout[/b][b] [/b]的设置可修改[b]Server.ScriptTimeout[/b]的值,[b]使用ScriptTimeout属性以编程方式对超时值进行的设置优先于Web.config设置。[/b]
<span style="font-family: 'Microsoft YaHei';"><system.web>
 <compilation debug="false" targetFramework="4.0" />
 <!-- 设置为600秒 Server.ScriptTimeout = 600 -->
 <httpRuntime executionTimeout="600"/>
</system.web></span>

[b]方法三:[/b]设置HttpRuntimeSection.ExecutionTimeout 的值 (经测试,无效!!!不知如何使用!)[url=https://msdn.microsoft.com/zh-cn/library/system.web.configuration.httpruntimesection.executiontimeout(VS.80).aspx]https://msdn.microsoft.com/zh-cn/library/system.web.configuration.httpruntimesection.executiontimeout(VS.80).aspx[/url]
[u]复制代码[/u] 代码如下:
System.Web.Configuration.HttpRuntimeSection configSection = new System.Web.Configuration.HttpRuntimeSection(); configSection.ExecutionTimeout = TimeSpan.FromSeconds(100);
[b]方法四:[/b]IIS配置 修改 脚本超时 值 [img]http://files.jb51.net/file_images/article/201609/201609280917342.png[/img] [img]http://files.jb51.net/file_images/article/201609/201609280917343.png[/img] 这个未确定 网站→高级设置: [img]http://files.jb51.net/file_images/article/201609/201609280917344.png[/img] 一样未确定 应用程序池→高级设置: [img]http://files.jb51.net/file_images/article/201609/201609280917345.png[/img] [b]注意:[/b]如果页面使用了 UpdatePanel,UpdatePanel 内部的请求分以下两种情况: ①设置的超时值 >=90秒,UpdatePanel 内部的请求超时值将变为 90 秒! ② 设置的超时值 <90秒,UpdatePanel 内部的请求超时值将变为 所设置的值! 下图Server.ScriptTimeout= 5 秒,点击UpdatePanel 内部的按钮,Thread.Sleep(20 * 1000) 秒,请求超时,但是页面看不到报错信息! 而点击UpdatePanel 外部的按钮,则会报如图1的 “请求超时”的错误信息! [img]http://files.jb51.net/file_images/article/201609/201609280917356.png[/img] 下图Server.ScriptTimeout= 100 秒,点击UpdatePanel 内部的按钮,Thread.Sleep(95 * 1000)//停止95秒; 实际上到90秒就超时了(如下面第二图)而点击UpdatePanel 外部的按钮,Thread.Sleep(95 * 1000)//停止95秒 ,请求成功! [img]http://files.jb51.net/file_images/article/201609/201609280917357.png[/img] [img]http://files.jb51.net/file_images/article/201609/201609280917358.png[/img] =======================================================================================================================[b]全局超时时间[/b] 服务器上如果有多个网站,希望统一设置一下超时时间,则需要设置 Machine.config 文件中的 ExecutionTimeout 属性值。Machine.config 文件位于%SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\目录中。 <httpRuntime executionTimeout="600" /> 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部