⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 利用global.asa计划执行程序.htm

📁 较为详细的介绍了asp自定义的各种函数,方便asp的各种开发.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
    <TD width=753></TD>
    <TD bgColor=#297dff width=1> </TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
  <TBODY>
  <TR vAlign=top>
    <TD bgColor=#297dff width=1> </TD>
    <TD width=753>
      <TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
        <TBODY>
        <TR>
          <TD bgColor=#297dff colSpan=2 height=20><FONT color=#ceffff>&nbsp;→ 
            <A href="http://www.aspsky.net/article/index.asp?classid=2"><FONT 
            color=#ceffff>ASP技术</FONT></A> &gt;&gt; <A 
            href="http://www.aspsky.net/article/index.asp?classid=2&amp;Nclassid=2"><FONT 
            color=#ceffff>ASP应用</FONT></A> &gt;&gt; 
          《利用global.asa计划执行程序》</FONT></TD></TR>
        <TR>
          <TD bgColor=#586011 colSpan=2 height=1><SPACER type="block" 
            width="1"></TD></TR>
        <TR>
          <TD colSpan=2 height=7></TD></TR>
        <TR>
          <TD align=middle class=p4 
            colSpan=2><B>利用global.asa计划执行程序</B></FONT><BR>2001-5-8&nbsp;&nbsp;动网先锋 
          </TD></TR>
        <TR>
          <TD class=p4 colSpan=2>
            <BLOCKQUOTE><BR>其实就是利用文件“global.asa”!许多ASP编程新手都想知道这东西是什么?事实上,global.asa就是一个事件驱动程序,其中共包含4个事件处理过程: 
              Application_OnStart、Application_OnEnd、Session_OnStart 和 
              Session_OnEnd。<BR>   
              当网站的一个应用程序的页面第一次被用户访问时,global.asa就被装载进内存。当应用程序(application 
              )启动、结束,或者会话(session)开始、结束时,你就可以加入需要执行的脚本代码。<BR>   
              利用一些技巧,你就可以使用global.asa文件达到计划执行任务的目的。<BR>   
              这里有一个例子:“跟踪网站有多少访问者;在访问量达到100时,计数器复位到0,并且执行你事先编制的代码”。当然,根据自己的需要,你可以调整访问量的上限数目100。<BR>   
              global.asa的内容如下:
              <P></P>
              <P>&lt; SCRIPT LANGUAGE=VBScript RUNAT=Server &gt;</P>
              <P>Sub Application_OnStart<BR>Application("SessionCount") = 
              0<BR>End Sub</P>
              <P>Sub Session_OnStart</P>
              <P>Application.Lock<BR>Application("SessionCount") = 
              Application("SessionCount") + 1<BR>Application.Unlock</P>
              <P>If Application("SessionCount") &gt; 100 Then</P>
              <P>Application.Lock<BR>Application("SessionCount") = 
              0<BR>Application.Unlock</P>
              <P>' Here you would put any code you need to run<BR>' do not 
              surround the code with &lt; % % &gt; tags<BR>' For example you 
              might run a database query that checks for expired accounts</P>
              <P>End if</P>
              <P>End Sub</P>
              <P>&lt; /SCRIPT &gt; </P>
              <P>   
              下面,让我们看看一天内执行4次某任务的情况。你可以将日期和时间的值存储在一个文本文件中,并且周期性地检查它。当时间过去6个小时时,写入新的日期与时间到这个文本文件中,并且,启动你想要执行的任务。你可以改变 
              “6”这个数值,从而更多或者更少地执行任务。</P>
              <P>   虽然,上面的方法需要对文本文件设置读、写权限后才能正确执行,但这仍不失为一个非常聪明的解决方案!</P>
              <P>   
              在这个例程中,每有15个新访问者时,就检查文本文件一次。当然,你可以调整“15”的数值,或者设定每当有新访问者时,都检查文本文件一次。但这样处理,无疑会加重站点的负载,浪费服务器的资源!总之,检查的频度由你自己考虑后设定。</P>
              <P>   例子中,必须保证初次写入文本文件的日期与时间的合法性,否则,当程序首次读入一个空值时,就会发生运行错误。</P>
              <P>   比如:将 6/30/99 6:58:45 PM 初始写入文本文件的第一行。</P>
              <P>   
              当前,也可以加入一些代码,用来检查日期与时间的写法,并且处理出错信息。但初始写入一个合法的日期与时间数值,将会更简单一些。</P>
              <P>   global.asa的内容如下:</P>
              <P>&lt; SCRIPT LANGUAGE=VBScript RUNAT=Server &gt;</P>
              <P>Sub Application_OnStart<BR>Application("SessionCount") = 
              0<BR>End Sub</P>
              <P>Sub Session_OnStart</P>
              <P>Application.Lock<BR>Application("SessionCount") = 
              Application("SessionCount") + 1<BR>Application.Unlock</P>
              <P>If Application("SessionCount") &gt; 15 Then</P>
              <P>Application.Lock<BR>Application("SessionCount") = 
              0<BR>Application.Unlock</P>
              <P>Set ObjMyFile = 
              CreateObject("Scripting.FileSystemObject")<BR>Set OpenMyFile = 
              ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt"))<BR>MyFileValue 
              = OpenMyFile.ReadLine<BR>OpenMyFile.Close</P>
              <P>If DateDiff("h",MyFileValue,NOW) &gt; 6 Then</P>
              <P>' Here you would put any code you need to run<BR>' do not 
              surround the code with &lt; % % &gt; tags<BR>' For example you 
              might run a database query that checks for expired accounts</P>
              <P>Set WriteMyFile = 
              ObjMyFile.CreateTextFile(Server.MapPath("last-update.txt"))<BR>WriteMyFile.WriteLine(NOW)<BR>WriteMyFile.Close</P>
              <P>End if <BR>   End If</P>
              <P>End Sub</P>
              <P>&lt; /SCRIPT &gt;</P>
              <P><BR>   请注意:还有许多更好的方法达到检查的目的,这篇文章的目的是想起到抛砖引玉的作用。</P>
              <P>   
              同时请记住:WEB站点的应用程序一定要设置为一个Application,这样“global.asa”文件才能起作用。许多虚拟域默认为Application,但下层的目录却不是。</P>
              <P>最后的一点提示:在将代码写入global.asa前,请先写入一个“ASP”文件中进行测试。如果测试失败,那么在global.asa中也将不能运行成功。同时,确认文本文件的路径是正确的。<BR><BR><BR></P></BLOCKQUOTE></TD></TR>
        <TR>
          <TD class=p4 vAlign=top width="50%">
            <BLOCKQUOTE>原作者:allsky(转)<BR>来 源:chinaasp<BR>共有1730位读者阅读过此文<BR>【<A 
              href="http://bbs.aspsky.net/list.asp?boardid=1">发表评论</A>】 
            </BLOCKQUOTE></TD>
          <TD class=p4 vAlign=top width="50%">
            <P>
            <LI><FONT color=#0772b1>上篇文章</FONT>:<A 
            href="http://www.aspsky.net/article/list.asp?id=1935">通过地址栏传递参数.通过url传递参数</A> 
            <BR>
            <LI><FONT color=#0772b1>下篇文章</FONT>:<A 
            href="http://www.aspsky.net/article/list.asp?id=1937">ASP.NET连SQL7接口源代码</A> 
            </LI></TD></TR>
        <TR>
          <TD bgColor=#297dff class=p4 height=20 width="50%"><FONT 
            color=#ceffff>&nbsp;→ 本周热门</FONT></TD>
          <TD bgColor=#297dff class=p4 width="50%"><FONT color=#ceffff>&nbsp;→ 
            相关文章</FONT></TD></TR>
        <TR>
          <TD bgColor=#586011 colSpan=2 height=1><SPACER type="block" 
            width="1"></TD></TR>
        <TR>
          <TD colSpan=2 height=7></TD></TR>
        <TR>
          <TD class=p4 vAlign=top width="50%">
            <LI><A href="http://www.aspsky.net/article/list.asp?id=1510" 
            target=_top title="SQL Server 7.0 入门(一)">SQL Server 7.0 
            入门(...</A>[<FONT color=red>7239</FONT>]<BR>
            <LI><A href="http://www.aspsky.net/article/list.asp?id=1540" 
            target=_top title=PHP4实际应用经验篇(1)>PHP4实际应用经验篇(1)</A>[<FONT 
            color=red>7135</FONT>]<BR>
            <LI><A href="http://www.aspsky.net/article/list.asp?id=1536" 
            target=_top 
            title=无组件文件上传代码实例(支持多文件上传及文件和input域混合上传)>无组件文件上传代码实例(支持多文件上...</A>[<FONT 
            color=red>6029</FONT>]<BR>
            <LI><A href="http://www.aspsky.net/article/list.asp?id=2557" 
            target=_top title=树型结构在ASP中的简单解决>树型结构在ASP中的简单解决</A>[<FONT 
            color=red>5757</FONT>]<BR>
            <LI><A href="http://www.aspsky.net/article/list.asp?id=1545" 
            target=_top title=PHP4实际应用经验篇(6)>PHP4实际应用经验篇(6)</A>[<FONT 
            color=red>5599</FONT>]<BR>
            <LI><A href="http://www.aspsky.net/article/list.asp?id=2563" 
            target=_top title=一个老个写的无组件上传>一个老个写的无组件上传</A>[<FONT 
            color=red>5014</FONT>]<BR>
            <LI><A href="http://www.aspsky.net/article/list.asp?id=1542" 
            target=_top title=PHP4实际应用经验篇(3)>PHP4实际应用经验篇(3)</A>[<FONT 
            color=red>4731</FONT>]<BR></LI></TD>
          <TD class=p4 vAlign=top width="50%">
            <LI><A 
            href="http://www.aspsky.net/article/list.asp?id=1936">利用global.asa计划执行程序</A><BR>
            <LI><A 
            href="http://www.aspsky.net/article/list.asp?id=1796">深入研究Application和Session对象(包括global.asa)3</A><BR>
            <LI><A 
            href="http://www.aspsky.net/article/list.asp?id=1795">深入研究Application和Session对象(包括global.asa)2</A><BR>
            <LI><A 
            href="http://www.aspsky.net/article/list.asp?id=1794">深入研究Application和Session对象(包括global.asa)1</A><BR>
            <LI><A 
            href="http://www.aspsky.net/article/list.asp?id=1217">妙用asp+的global.asax</A><BR></LI></TD></TR>
        <TR>
          <TD colSpan=2 height=7></TD></TR></TBODY></TABLE>
    <TD bgColor=#297dff width=1> </TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
  <TBODY>
  <TR>
    <TD bgColor=#297dff height=1><SPACER type="block" 
width="1"></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
  <TBODY>
  <TR>
    <TD align=middle height=30></TD></TR></TBODY></TABLE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
  <TBODY>
  <TR>
    <TD align=middle class=p2 width="100%">
      <TABLE border=0 cellPadding=0 cellSpacing=0 width=755>
        <TBODY>
        <TR>
          <TD align=middle class=p2 width="100%">
            <P align=center><A 
            href="http://www.aspsky.net/produce/index.asp">客户服务</A> -- <A 
            href="http://www.aspsky.net/aspads.asp">广告合作</A> -- <A 
            href="http://www.aspsky.net/about.asp">关于本站</A> -- <A 
            href="http://www.aspsky.net/tell.asp">联系方法</A><BR><BR>动网先锋版权所有 <FONT 
            face=Verdana, size=1 Arial, Helvetica, sans-serif>Copyright &copy; 
            2000-2001 <B>AspSky<FONT color=#cc0000>.Net</FONT></B>, All Rights 
            Reserved .</FONT> 
</P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -