Coldfusion错误处理 [英] Coldfusion error handling
问题描述
我正在尝试创建一些自定义错误页面,以向我们的开发人员发送电子邮件,告知他们Coldfusion中出现404或500错误。
I am trying to create some custom error pages that email our developers that there has been an 404 or 500 error in coldfusion. Also it would be helpful if within the email it gives the error variables.
我在Coldfusion中设置了一个错误页面,并指出了IIS(7)。
I have set up a error page in coldfusion and have pointed IIS(7) at it.
也在我的application.cfm文件中声明以下内容:
Also in my application.cfm file I am declaring the following:
<cferror type="exception" template="#name#">
<cferror type="request" template="#name#">
<cferror type="validation" template="#name#">
<cferror type="monitor" template="#name#">
我的问题是在错误文件中我无法包含任何CF调用,CF似乎将它们剥离。
My problem is that within the error file I cannot include any CF calls, CF appears to stripe them out.
我做错什么了吗?
谢谢!
推荐答案
根据下面Travis的评论-虽然仍支持使用 cferror
标记,建议从Application.cfm转换为Application.cfc(如果尚未转换),并使用 onError
方法。使用 onError
方法时,下面列出的所有限制均不适用,并且所有CFML功能均可用。 此处是onError方法的ColdFusion 9文档。
As per Travis' comments below - while the use of the cferror
tag is still supported it is recommended to convert from Application.cfm to Application.cfc (if not already) and use the onError
method instead. All of the restrictions that I have listed below do not apply when using the onError
method and all CFML functionality is available. Here is the ColdFusion 9 documentation for the onError method.
有关错误处理的ColdFusion文档详细。但是对于有关 cferror
标记的特定问题,您需要认识到,发生错误时ColdFusion可以执行的操作存在一些限制,甚至取决于错误的类型。这是摘录自此页面:
There is an entire section of the ColdFusion documentation regarding error handling in detail. But for your specific question regarding the cferror
tag you need to realize that there are limitations to what ColdFusion can do when an error occurs and even that depends on the type of error. Here is an excerpt taken from this page:
下表列出了适用于错误应用程序页面的
规则和注意事项:
The following table lists the rules and considerations that apply to error application pages:
验证
- 不能使用CFML标签
- 可以使用HTML标签
- 可以使用
Error.InvalidFields
,Error.validationHeader
和Error.validationFooter
变量用数字符号(#)括起来 - 不能使用任何其他CFML变量
- Cannot use CFML tags
- Can use HTML tags
- Can use the
Error.InvalidFields
,Error.validationHeader
, andError.validationFooter
variables by enclosing them with number signs (#) - Cannot use any other CFML variables
请求
- 不能使用CFML标签
- 可以使用HTML标记
- 可以将九个CFML错误变量(例如
Error.Diagnostics
)括起来使用带有数字符号的 - 不能使用其他CFML变量
- Cannot use CFML tags
- Can use HTML tags
- Can use nine CFML error variables, such as
Error.Diagnostics
, by enclosing them with number signs - Cannot use other CFML variables
E xception
- 可以使用完整的CFML语法,包括标签,函数和变量
- 可以使用九个标准CFML错误变量和cfcatch变量。使用
Error
或cferror
作为这两种变量的前缀 - 可以使用其他应用程序定义的CFML变量
- 要显示任何CFML变量,请使用cfoutput标签
- Can use full CFML syntax, including tags, functions, and variables
- Can use nine standard CFML Error variables and cfcatch variables. Use either
Error
orcferror
as the prefix for both types of variables - Can use other application-defined CFML variables
- To display any CFML variable, use the cfoutput tag
摘录自此页面关于每种异常类型的可用错误变量:
Excerpt taken from this page regarding the available error variables for each exception type:
仅验证
error.validationHeader Validation message header text.
error.invalidFields Unordered list of validation errors.
error.validationFooter Validation message footer text.
请求与例外
error.diagnostics Detailed error diagnostics from ColdFusion.
error.mailTo E-mail address (same as value in cferror.MailTo).
error.dateTime Date and time when error occurred.
error.browser Browser that was running when error occurred.
error.remoteAddress IP address of remote client.
error.HTTPReferer Page from which client accessed link to page where error occurred.
error.template Page executing when error occurred.
error.generatedContent The content generated by the page up to the point where the error occurred.
error.queryString URL query string of client's request.
仅例外
error.message Error message associated with the exception.
error.rootCause The root cause of the exception. This structure contains the information that is returned by a cfcatch tag.
For example, for a database exception, the SQL statement that caused the error is in the error.RootCause.Sql variable.
For Java exceptions, this variable contains the Java servlet exception reported by the JVM as the cause of the "root cause" of the exception.
error.tagContext Array of structures containing information for each tag in the tag stack. The tag stack consists of each tag that is currently open.
error.type Exception type.
注意:如果type = exception,则可以将前缀cferror替换为Error;例如cferror.diagnostics,cferror.mailTo或cferror.dateTime。
这篇关于Coldfusion错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!