coldfusion - 转动重定向ON和OFF?
问题描述
我有一个带有 200 多个<cflocation>
标签的旧式 ColdFusion 系统,并且希望能够轻松地从我的Application.cfm
.
除了必须向每个文件添加条件语句之外,最好的方法是什么?
想到扩展<cflocation>
标签以首先检查true
/false
标志的想法出现了,但我以前从未做过任何高级的事情,也不知道从哪里开始。
解决方案
您不能在 CF 中扩展/继承本机标签。您可以使用自定义标记,然后将所有出现的<cflocation
(native)搜索替换为<cf_location
(custom),其中包含您的重定向标志。
应用程序.cfm
<cfset APPLICATION.allowRedirects = false>
location.cfm(本机的包装器cflocation
)
<!--- if the variable doesn't exist for some reason, process the regular cflocation --->
<cfif (
(not isDefined("APPLICATION.allowRedirects")) or
(isBoolean(APPLICATION.allowRedirects) and APPLICATION.allowRedirects)
)>
<cflocation attributeCollection="#ATTRIBUTES#">
<!--- cflocation ends the request automatically --->
</cfif>
<!--- print debug info --->
<cfif structKeyExists(ATTRIBUTES, "url")>
<cfoutput>Attempted to redirect to: #encodeForHtml(ATTRIBUTES["url"])#</cfoutput>
</cfif>
<!--- abort the request without redirecting --->
<cfabort>
另一种方法是<cfmodule>
. 搜索替换所有出现的<cflocation
with <cfmodule template="/mytags/location.cfm"
。这里的优势:您不需要location.cfm
通过模板路径customTagPaths
进行注册。cfmodule
更简单:只需一次搜索替换所有<cflocation>
标签并将它们包装在条件中。您不必手动检查 200 个文件。
(这适用于 Sublime Text,但任何适当的编辑器都可以为您执行此操作。)
查找:((<cflocation[^>]+>)
启用正则表达式!)
替换:(<cfif APPLICATION.allowRedirects>\1</cfif>
是\1
反向引用,一些编辑器使用$1
)
推荐阅读
- pytorch - 如何找到 torch.nn.conv_transpose2d 和 max_unpool2d 的参数?
- java - docker中的内存使用超过了xmx控制或小于xms
- javascript - momentjs 不会按照指定的时区更改日期/时间
- c# - 身份确认电子邮件问题
- unity3d - Unity - 球弹跳
- java - 在 vscode 中运行 Java:“构建失败,要继续吗?” 如果我选择“继续”,它工作正常
- vue.js - 在 vuepress 中,如何将一些 md 内容动态呈现为客户主题(vue 模板)
- powershell - 如何让powershell等待批处理文件完成远程服务器上所有命令的执行
- c# - 来自鼠标单击事件的多个正确 If 语句
- guice - 我可以在不扩展 AbstractModule 的类中有一个 Guice @Provides 方法吗?