Coldfusion:检测是否由调度程序运行
有没有办法让 ColdFusion 应用程序知道它是从调度程序运行还是从浏览器运行?理想情况下,我想设置一个会话标志,例如 Application.cfm 中的“isScheduled”以在整个应用程序中使用。
编辑 我最终检查了用户代理,并且它正在本地运行(以提高安全性),并且(因为它在 Application.cfm 中运行)该页面位于允许调度的文件夹中:
Request.isScheduled = FindNoCase("CFSCHEDULE",CGI.HTTP_USER_AGENT) and (Find("10.",CGI.REMOTE_ADDR)==1 或查找(“198.162。”,CGI.REMOTE_ADDR)==1) 和 FindNoCase("预定",CGI.CF_TEMPLATE_PATH);
Is there a way for a ColdFusion app to know whether it is being run from the scheduler vs. from a browser? Ideally, I'd like to set a Session flag, for instance "isScheduled" in Application.cfm to be used throughout the app.
EDIT
I ended up checking the user agent, and that it is being run locally (to improve security), and (since it is running in Application.cfm) that the page is in the folder which allows scheduling:
Request.isScheduled = FindNoCase("CFSCHEDULE",CGI.HTTP_USER_AGENT)
and (Find("10.",CGI.REMOTE_ADDR)==1
or Find("198.162.",CGI.REMOTE_ADDR)==1)
and FindNoCase("scheduled",CGI.CF_TEMPLATE_PATH);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查用户代理。用户代理是“CFSCHEDULE”,但请先确认这一点。
Check for the user agent. The user agent is "CFSCHEDULE" but please confirm this first.
我将 Application.cfm 逻辑嵌套在 cfif 中,用于检查是否定义了参数(“cron”)。如果是,那么它会跳过应用程序中的所有其余逻辑,例如身份验证、标题垃圾等。
然后,当我设置计划任务时,我会传入我想要使用 cron 参数(http:// mysite.com/scheduledtasks.cfm?cron=yo)
I nest my Application.cfm logic in a cfif, that checks to see if a parameter ('cron') is defined. If it is, then it skips all of the rest of the logic in Application like authentication, header crap, etc.
Then when I set up the scheduled tasks I pass in the URL I want to hit with the cron parameter (http://mysite.com/scheduledtasks.cfm?cron=yo)
我不确定,但如果应用程序通过调度程序运行,那么 cgi.remote_address 必须与您可以跟踪的所有请求相同......并标记“isSchedule”......
I am not sure but if application run through scheduler then cgi.remote_address must be same for all request that you can track.....and mark "isSchedule"....
让任务调度程序运行一系列任务,然后触发实际任务是一种常见的做法。即,您运行了“dailytask.cfm,其中 cf 包含您要运行的任务。您现在可以向其中添加 url.parameters 或其他内容来识别触发器的来源。
It's a common practice to let the task scheduler run a list of tasks which in tern trigger the actual tasks. I.e. you ran "dailytask.cfm which cfincludes the task that you want to run. You can now add url.parameters or other things to it to identify the source of the trigger.