日本xxxx18视频在线观看-日本xxxx1819-日本xxxwww在线观看-日本xxx-日本xx-日本www在线视频

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

利用global.asa定時執(zhí)行ASP

admin
2012年1月14日 12:46 本文熱度 3534
Using the global.asa to schedule ASP code execution.
Have you ever had some asp code that needed to execute every once in a while but, you just didn't know how to do it.


There is a solution that doesn't involve running any scheduling or scripting software on the server and is actually very easy to get working.


You see... there is thing called the "global.asa". Most ASP newbies probably wonder what the heck it even is. The Global.asa file is event driven. It can contain four event procedures: Application_OnStart, Application_OnEnd, Session_OnStart, and Session_OnEnd.


The global.asa is basically loaded into memory the first time any user views a page on your Web application. There are event procedure stubs that can contain script you want to be executed when the application starts or ends, or when the session starts or ends.


With some tricky coding you can use this file to schedule code to execute. At least around the time you need it to, this won't be able to make it execute at exactly a certain time.


Here is the 1st example. It simply keeps track of how many visitors have been to your site and after 100 it resets the count back to 0 and executes whatever code you need to run. Obviously you'll need to adjust the "100" to whatever makes sense for the amount of visitors your site receives.


Contents of the global.asa are below.


<SCRIPT LANGUAGE=VBScript RUNAT=Server>


Sub Application_OnStart
Application("SessionCount") = 0
End Sub


Sub Session_OnStart


Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application.Unlock


If Application("SessionCount") > 100 Then


Application.Lock
Application("SessionCount") = 0
Application.Unlock


' Here you would put any code you need to run
' do not surround the code with <% %> tags
' For example you might run a database query that checks for expired accounts


End if


End Sub


</SCRIPT>


Now lets say you want something to execute 4 times a day. You can store the date & time in a text file and check it periodically. When the date and time get to be more than 6 hours old the code will write the new date & time to the text file and then execute the code you want to run. You could change the "6" to whatever you want and therefore execute the code more or less often,


This is a pretty slick solution though it requires correct permissions to the text file for reading & writing. If not you'll get an error.


In this example we are checking the text file every 15 visitors. You can adjust this amount or remove the "check" completely so that it checks the file every time, but why check the file every time when you have a very busy site ? That would just be a waste of server resources ,but it is up to you how far you want to take this.


In this example you need to start the text file off with a valid date& time or else you will get an error because the script will read in an empty value the 1st time.


EXAMPLE: put 6/30/99 6:58:45 PM in the 1st line of the text file.


You could add code to check for that and handle the error, but I didn't really care at the time so I didn't do that. As long as there is a date there when it starts it will keep working.


Contents of the global.asa are below.


<SCRIPT LANGUAGE=VBScript RUNAT=Server>


Sub Application_OnStart
Application("SessionCount") = 0
End Sub


Sub Session_OnStart


Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application.Unlock


If Application("SessionCount") > 15 Then


Application.Lock
Application("SessionCount") = 0
Application.Unlock


Set ObjMyFile = CreateObject("Scripting.FileSystemObject")
Set OpenMyFile = ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt"))
MyFileValue = OpenMyFile.ReadLine
OpenMyFile.Close

If DateDiff("h",MyFileValue,NOW) > 6 Then


' Here you would put any code you need to run
' do not surround the code with <% %> tags
' For example you might run a database query that checks for expired accounts

Set WriteMyFile = ObjMyFile.CreateTextFile(Server.MapPath("last-update.txt"))
WriteMyFile.WriteLine(NOW)
WriteMyFile.Close

End if
End If


End Sub


</SCRIPT>



Please Note: There are many ways to make this better and many different possible variations of what to check for before executing the desired code. This article should get you started and give you some ideas.


Also remember that if the web is not set up to run as an application the "global.asa" will not run. You'll need to make sure the web is an application. Most Virtual Domains are by default, but sub webs usually are not.


For the sub webs to run the 'global.asa" they need to be an application as the root usually is. In NT this is accomplished via the Internet Service Manager under the properties of the sub web you want to make an application.


Here is what it looks like in IIS4.



One Last Thing: Before you put any code in your Global.asa to execute during events test it first in a regular ".asp" page. If it doesn't run there it sure isn't going to run in your global.asa. Also make sure you file paths are correct for the text file. Everything has to be perfect for this sort of thing to work.


Good Luck


該文章在 2012/1/14 12:46:25 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 欧美又色又爽又黄刺激免 | 日本免费一区二区在线观看 | 国产一区二区三区四区精华 | 欧美日韩偷拍一区二区 | 国产精品.xx视频.xxtv | 九色99| 国产欧美亚洲精品一二三区 | 精品一区二区免费 | 成人性生交大片免费看 | 国产精品亚洲视频在线观看 | 爱如潮水视频在线观看 | 日韩精品在线免费观看 | 国产精品无不卡一区二区 | 国产精品二 | 国产性生交xxxxx免费 | 成人国产免 | 国产青草视频在线观看免费影院 | 国产香蕉在线观 | 成人日韩熟女高清视频一区 | 欧美性色 | 亚洲精品免费日日日夜夜夜夜 | 精品日本亚洲18 | 国产精品综合一区二区在线观看 | 欧美视频专区一二在线观看 | 国产大片免费线上观 | 国产蜜桃臀好大在线观看 | 国产偷窥不卡视频 | 国产九区 | 欧美自拍无毒不卡 | 国产欧美日韩一区二 | 欧美曰韩一区二区三区 | 国产国产成年人 | 欧洲亚洲精品免费 | 国产精品不卡一区二区三区 | 好吊妞国产欧美日韩观看在线 | 欧美肉大捧一进一出免费视频 | 日韩极品成年人在线观看高清 | 国产在线精品一区二区夜色 | 国产一级中文字幕 | 日韩精品大秀视频在线观看 | 日本亚洲最大的色成网站www |