如何设置ASP.NET页面的运行超时时间

全局超时时间

服务器上如果有多个网站,希望统一设置一下超时时间,则需要设置 Machine.config 文件中的 ExecutionTimeout 属性值。
Machine.config 文件位于 %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ 目录中。
例如:

?
1
<httpRuntime executionTimeout= "90" maxRequestLength= "4096" useFullyQualifiedRedirectUrl= "false" minFreeThreads= "8" minLocalRequestFreeThreads= "4" appRequestQueueLimit= "100" />

单个站点超时时间
Web.config配置文件中设置http请求运行时间:

?
1
2
3
<system.web>
<httpRuntime maxRequestLength= "102400" executionTimeout= "720" />
</system.web>


这里设置的为720秒,前面的属性maxRequestLength一般用于用户上传文件限制大小!默认一般为4096 KB (4 MB)。

单个页面请求超时时间
对于单个页面,可以使用Server.ScriptTimeout来设定超时。

?
1
Server.ScriptTimeout = 120;

 

注意:如果在Web.config里设置了debug属性,例如:<compilation debug="true" targetFramework="4.0">
此时,ScriptTimeout会被忽略。

 

 

 

 

 

Asp.Net各种超时问题总结

 
在数据库或者请求操作时,如果选择的时间段过短或操作数据量过大,就会遇到"请求超时"的的问题,网络上提供很多解决方案,但普遍不完善,根据个人经验及参考网络解决方案,先将其汇总如下:

   
根据错误类型,大致分为如下几种情况
  1:Asp.net请求超时
  2:IIS请求超时
  3:数据库连接超时
  4:
数据库操作超时
  5:应用程序池回收(低)
  6:Webservice等服务请求超时 

下面根据上述情况一一作出处理
1:Asp.net请求超时
  http请求超时可以在webconfig中进行全局配置,(单位为秒,默认为90秒)如下
    <system.web> 

     <httpRuntime maxRequestLength="102400" executionTimeout="180" /> 

    system.web>

2:IIS请求超时
  直接去IIS进行设置:IIS-网站-属性  
设置一个较大的值,但是不能太大,具体情况具体分析。

3:数据库连接超时
  在配置数据库连接字符串的时候一起配置
  <connectionStrings>
    <add
name="MarketingMate" connectionString="Data Source=192.168.1.1;
Database=MarketingMate; User Id=sa; Password=123; Connect Timeout=30;Min Pool
Size=16;Max Pool
Size=100;"
       providerName="System.Data.SqlClient"/>   

  connectionStrings>

4.
数据库操作超时
  数据库操作超时目前还没有全局设置方法,只能设置Command类的CommandTimeOut属性(单位为秒,默认为30秒)
  
context.CommandTimeout = 180; 


 5:应用程序池回收(底)这种出现的情况很低,请酌情设置
  应用程序池会在一定的时间内回收线程,直接设置即可:应用程序池--属性--回收工作进程


 6:Webservice等服务请求超时 (这种是参考网上提供的解决方法,本人没遇到过)
  扩大代理类的超时限制,默认是90秒 
,即在调用方法前指定超时时间。
  [csharp]YourWebService yws = new YourWebService();
yws.Timeout = 1200000; //20分钟,单位是毫秒[/csharp]
  如果将 Timeout 属性设置为
Timeout.Infinite,则指示该请求无超时。即使 XML Web services 客户端可以将 Timeout 属性设置为无超时,Web
服务器仍可以在服务器端使请求超时。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
.net C#线程超时的解决方案,使用的时候在被调线程入口调用一下这个方法就可以。更多详细代码见附件 Report.RegisterThread(Report.GetCurrentWin32ThreadID(),Thread.CurrentThread); #region 获取当取线程的ThreadID [DllImport("Kernel32", EntryPoint = "GetCurrentThreadId", ExactSpelling = true)] public static extern Int32 GetCurrentWin32ThreadID(); #endregion #region 登记访问任务子线程 /// /// 访问任务子线程 /// public static Hashtable TaskThreadIDTable = Hashtable.Synchronized(new Hashtable()); private static int[] TaskThreadIDs { get { int[] IDs = new int[TaskThreadIDTable.Keys.Count]; TaskThreadIDTable.Keys.CopyTo(IDs, 0); return IDs; } } public static void RegisterThread(int _threadid, System.Threading.Thread thread) { if (!TaskThreadIDTable.ContainsKey(_threadid)) TaskThreadIDTable.Add(_threadid, thread); if (!ExitInvalidThreadLoopRunning) { Thread ExitInvalidThreadLoopThread = new Thread(new ThreadStart(ExitInvalidThreadLoop)); ExitInvalidThreadLoopThread.Priority = ThreadPriority.AboveNormal; ExitInvalidThreadLoopThread.Start(); } } #endregion #region 关闭,退出超时的用户线程 private static DateTime ExitInvalidThreadLoop_LastRunTime = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); private static bool ExitInvalidThreadLoopRunning { get { return DateTime.Now.Subtract(ExitInvalidThreadLoop_LastRunTime).TotalMinutes 10) { try { Thread thread = (Thread)TaskThreadIDTable[t.Id]; thread.Abort(); } catch { } t.Dispose(); } } #endregion } #endregion

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值