找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 603|回复: 17

哪位E文达人翻译一下,看的晕晕的

[复制链接]

676

主题

5002

回帖

601

积分

新手上路

积分
601
QQ
发表于 2007-1-9 10:48:44 | 显示全部楼层 |阅读模式
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

250

主题

1万

回帖

9700

积分

超级版主

积分
9700

云间城纪念勋章

QQ
发表于 2007-1-9 10:49:55 | 显示全部楼层
= =|||代码?

676

主题

5002

回帖

601

积分

新手上路

积分
601
QQ
 楼主| 发表于 2007-1-9 10:50:59 | 显示全部楼层
你就别管什么了。。翻译过来就行了。。

462

主题

2万

回帖

8420

积分

新手上路

买洗液,要认准恩威洁尔阴

积分
8420
发表于 2007-1-9 10:54:08 | 显示全部楼层
使用 global.asa 预定毒蛇密码实行。
你曾经有需要的一些毒蛇密码三不五时运行但是,你就是没有知道该如何做它。

有不包括跑任何的计划安排或手写体在伺候器上的软件而且是实际上很容易工作的解决。

你见到。。。 有被称为 " global.asa" 的事物。 大多数的毒蛇 newbies 或许怀疑什么木栅它甚至是。 Global.asa 文件是事件受到驱策的。 资讯科技能包含四个事件程序: Application_OnStart , Application_OnEnd , Session_OnStart 和 Session_OnEnd。

global.asa 基本上被载入记忆第一计时任何的使用者看在你的网络申请上的页。当申请开始或结束的时候,有事件程序能包含你想要被运行的手写体的断株, 或当会议开始或结束。

藉由一些狡猾的编码你能使用这一个文件预定编码运行。 至少在当你需要它的时候周围到,这将会无法在完全特定的时间使它运行。

第一个例子在这里。 资讯科技只是掌握的资讯访客曾经到过你的位置多少,而且在 100 之后它把计数重新设定回 0 而且运行你需要跑的任何密码。 明显地你将会需要调整 "100" 到不论什么为你的位置接受的访客数量有道理。

global.asa 的内容在下面。

<手写体语言= VBScript RUNAT=伺候器>

代替 Application_OnStart
申请 (" SessionCount")=0
结束替代人员

代替 Session_OnStart

申请。锁
申请 (" SessionCount")= 申请 (" SessionCount")+1
申请。开启

如果申请 (" SessionCount")>100 然后

申请。锁
申请 (" SessionCount")=0
申请。开启

' 这里你会放你需要跑的任何密码
' 不要包围密码 <%%> 标签
' 举例来说你可能跑一个数据库疑问检查对于期满的帐户

结束如果

结束替代人员

</手写体>

现在让你想要某事一天 4 次运行的发言权。 你能定期地储存一个文字档的日期和时间而且检查它。 当日期和时间开始的时候很旧密码将会写新的日期 & 时间给文字档然后运行你想要跑的密码。 你可以改变 "6" 到无论你想要因此或多或少时常运行密码什么,

虽然它需要为阅读和写作正确的许可对文字档,这是相当光滑的解决。 如果不你将会拿一个错误。

在这一个例子中我们正在检查文字档每个 15个访客。 你能完全地调整这数量或除去 " 检查 " ,以便它每一次检查文件,但是当你有一个非常忙碌的位置时候为什么每一次检查文件 ? 那会仅仅是一个伺候器资源的废物 , 但是依你的意思你想要轮流这多远。

在这一个例子中你需要走开以一个有效的日期和时间开始文字档,否则否则因为手写体将会在空的价值第一次中读,你将会拿一个错误。

例子: 把 6/30/99 下午 6:58:45 放入文字档的第一条线。

你可以增加密码对于那检查而且处理错误,但是我不真的在那时关心,如此我没有做那。 只要在那里有一个日期当它开始的时候 , 它将会保存工作。

global.asa 的内容在下面。

<手写体语言= VBScript RUNAT=伺候器>

代替 Application_OnStart
申请 (" SessionCount")=0
结束替代人员

代替 Session_OnStart

申请。锁
申请 (" SessionCount")= 申请 (" SessionCount")+1
申请。开启

如果申请 (" SessionCount")>15 然后

申请。锁
申请 (" SessionCount")=0
申请。开启

设定 ObjMyFile=CreateObject(" Scripting.FileSystemObject")
固定的 OpenMyFile=ObjMyFile.OpenTextFile(Server.MapPath("持续-update.txt"))
MyFileValue=OpenMyFile。ReadLine
OpenMyFile。结束

如果 DateDiff(" h" , MyFileValue,现在)>6 然后

' 这里你会放你需要跑的任何密码
' 不要包围密码 <%%> 标签
' 举例来说你可能跑一个数据库疑问检查对于期满的帐户

固定的 WriteMyFile=ObjMyFile.CreateTextFile(Server.MapPath("持续-update.txt"))
WriteMyFile.WriteLine(现在)
WriteMyFile。结束

结束如果
结束如果

结束替代人员

</手写体>


请注意: 有许多方法作该检查什么的这个比较好的和许多不同可能变化为在运行被需要的密码之前。 这一个文章应该拿你开始而且给你一些主意。

也记得,如果网没被建立跑如 " global.asa" 将不跑的一个申请。 你将会需要确定,网是一个申请。 大多数的虚拟领域预先设定地 , 但是附属的网通常是不。

对于替代人员设圈套跑那 'global.asa" 他们需要通常是如根的一个申请是。 在新台币中这在附属的网财产之下经由英特网服务经理是完成的你想要制造一个申请。

它所在 IIS4 中看起来像的在这里。


一件最后的事物: 在你之前把任何的密码放入你的 Global.asa 在事件期间运行在一个老客户中测试它第一 ".毒蛇"标明的页数。 如果它在那里不跑它当然不将在你的 global.asa 中跑。 也确定你申请路径对文字档是正确的。 每件事物必须让这种事物是完美的工作。

好运气
涊⑧炷婹説:厾沵媽哋萉蕏蓅!!!

250

主题

1万

回帖

9700

积分

超级版主

积分
9700

云间城纪念勋章

QQ
发表于 2007-1-9 10:54:23 | 显示全部楼层
第一句就认识use,the,to,翻译毛阿。。

676

主题

5002

回帖

601

积分

新手上路

积分
601
QQ
 楼主| 发表于 2007-1-9 10:56:06 | 显示全部楼层
4楼的寒一个,代码都被你翻译成中文了 - -!

250

主题

1万

回帖

9700

积分

超级版主

积分
9700

云间城纪念勋章

QQ
发表于 2007-1-9 10:58:24 | 显示全部楼层
= =|||在线翻译?

462

主题

2万

回帖

8420

积分

新手上路

买洗液,要认准恩威洁尔阴

积分
8420
发表于 2007-1-9 11:00:39 | 显示全部楼层
我没用过在线翻译
涊⑧炷婹説:厾沵媽哋萉蕏蓅!!!

250

主题

1万

回帖

9700

积分

超级版主

积分
9700

云间城纪念勋章

QQ
发表于 2007-1-9 11:03:22 | 显示全部楼层
= =|||那。。拜。。。

676

主题

5002

回帖

601

积分

新手上路

积分
601
QQ
 楼主| 发表于 2007-1-9 11:09:51 | 显示全部楼层
翻译的实在太搞笑了,看来还是要自己慢慢啃。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2026-12-4 08:09 , Processed in 0.019421 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表