2013-02-12 33 views
1

我正在嘗試創建一些自定義錯誤頁面,通過電子郵件向我們的開發人員指出在Coldfusion中出現404或500錯誤。如果在電子郵件中給出錯誤變量,它也會有幫助。Coldfusion錯誤處理

我在coldfusion中設置了一個錯誤頁面,並指出了IIS(7)。

也是我application.cfm文件我聲明如下:

<cferror type="exception" template="#name#"> 
<cferror type="request" template="#name#"> 
<cferror type="validation" template="#name#"> 
<cferror type="monitor" template="#name#"> 

我的問題是錯誤文件中我不能包括任何CF電話,CF出現條紋出來。

我做錯了什麼?

在此先感謝!

回答

1

您的錯誤文件是否具有.cfm擴展名?

此外,如果您每404發送一封電子郵件,您可能會打開自己的郵件炸彈攻擊。您可能會更好地添加Google Analytics之類的內容來檢查404s。 500錯誤可能意味着一些事情出錯了,所以CF可能不會發送電子郵件。

+0

我不會有400個錯誤的自定義頁面發送電子郵件只有500錯誤。該文件是一個.cfm文件。錯誤頁面顯示它只是去掉任何煩人的cf調用,因爲我希望能夠在文件中使用cf mail等。 – 2013-02-12 18:05:23

6

按以下Travis的意見 - 而採用cferror標籤仍然支持,建議從Application.cfm轉換成的Application.cfc(如果沒有的話),並使用onError方法來代替。當使用onError方法並且所有CFML功能可用時,下面列出的所有限制均不適用。 Here is the ColdFusion 9 documentation for the onError method.

詳細地有ColdFusion documentation regarding error handling的整個部分。但是,對於您的關於cferror標籤的具體問題,您需要認識到,發生錯誤時,ColdFusion可以執行的操作有限制,甚至取決於錯誤的類型。下面是從this page採取的摘錄:

下表列出了 規則和注意事項適用於錯誤的應用程序頁面:

驗證

  • 不能使用CFML標籤
  • 可以使用HTML標籤
  • 可以使用Error.InvalidFields,Error.validationHeaderError.validationFooter variab萊用數字符號(#)括起來
  • 不能使用任何其他CFML變量

請求

  • 不能使用CFML標籤
  • 可以使用HTML標記
  • 可以使用九個CFML錯誤變量,如Error.Diagnostics,用數字標記將它們括起來
  • 無法使用其他CFML變量

異常

  • 可以使用完整的語法CFML,包括變量,函數和變量
  • 可以使用9個標準CFML錯誤變量和cfcatch變量。二者必選其一Errorcferror作爲前綴兩種類型的變量
  • 可以使用其他應用程序定義的CFML變量
  • 顯示任何CFML變量,使用CFOUTPUT標籤從this page採取


摘錄有關每個異常類型的可用錯誤變量:

僅限驗證

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 = 「異常」,可以替代前綴cferror的錯誤;例如,cferror.diagnostics,cferror.mailTo或cferror.dateTime。

+0

我不得不投票,因爲您提供的所有詳細信息都使用cferror,但仍然可以接受,但在application.cfc中使用onerror函數會更好。你不受任何這些東西的限制,也不必擔心類型。在onError中,您可以使用任何標籤或腳本進行任何處理,並可以對每個變量作用域進行完全訪問,就像它是一個普通請求一樣。 – Travis 2013-02-12 19:01:37

+0

沒問題 - 我同意你的意見。我只是在OP特意詢問'cferror'時才發佈這個消息。我只能假設他仍然在使用'Application.cfm'。我認爲回答這個問題會比較容易,然後爲OP提供一個全新的體系結構。我相信這解釋了爲什麼'CF似乎將它們剝離'給OP。不過,你的觀點是有效的。 – 2013-02-12 19:08:42

+0

有效的假設。你實際上可以在application.cfc中使用cferror,並且只需花費很少的努力就可以轉換到application.cfc,在cf9上,它已經過期很久 – Travis 2013-02-12 19:19:55

1

使用模板是最準確的,例如... dbc.cfm。 寫郵件發送代碼在dbc.cfm中。

<cftry> 
     <cfquery name="GetData" datasource="#Application.ds#" dbtype="ODBC" username="#Application.UserName#" password="#Application.Password#"> 
      SELECT m.price 
      FROM productvendorsmap m 
      WHERE m.productid = <cfqueryparam cfsqltype="cf_sql_integer" value="#ProductId#"> 
      AND m.vendorid = <cfqueryparam cfsqltype="cf_sql_integer" value="#VendorIdd#"> 
     </CFQUERY> 
     <cfcatch type="Database"> 
      **<cfinclude template="dbc.cfm">** 
     </cfcatch> 
    </cftry>