JScriptアサーションを使用して、Elmah 1.1 RCの例外タイプをフィルタリングするにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/931130

質問

404に対する最初のバインディングが機能するため、ErrorFilTermoduleを適切にセットアップしましたが、JScriptセクションはまったく機能しないようです。 httpRequestValidationExceptionは、レポートメールでまだ送信されています。

<errorFilter>
  <test>
    <equal binding="HttpStatusCode" value="404" type="Int32" />
    <jscript>
      <![CDATA[
            // @assembly mscorlib
            // @assembly System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
            // @import System.IO
            // @import System.Web

            HttpStatusCode == 404
            || BaseException instanceof FileNotFoundException 
            || BaseException instanceof HttpRequestValidationException
            || BaseException instanceof HttpException
            /* Using RegExp below (see http://msdn.microsoft.com/en-us/library/h6e2eb7w.aspx) */
            || Context.Request.UserAgent.match(/crawler/i)
            || Context.Request.ServerVariables['REMOTE_ADDR'] == '127.0.0.1' // IPv4 only
            ]]>
    </jscript>
  </test>
</errorFilter>
役に立ちましたか?

解決

複数の状態がある場合、例にある方法(<equal> それから <jscript>)、あなたはエルマにどちらかと彼らまたは彼らに伝える必要があります。解決策は使用することです <and> また <or>, 、条件を論理的に組み合わせる方法に応じて。以下では、条件が適用される可能性があるため、2つを組んでいます。

<errorFilter>
  <test>
    <or>
        <equal binding="HttpStatusCode" value="404" type="Int32" />
        <jscript>
          <expression><![CDATA[
                // @assembly mscorlib
                // @assembly System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
                // @import System.IO
                // @import System.Web

                HttpStatusCode == 404
                || BaseException instanceof FileNotFoundException 
                || BaseException instanceof HttpRequestValidationException
                || BaseException instanceof HttpException
                /* Using RegExp below (see http://msdn.microsoft.com/en-us/library/h6e2eb7w.aspx) */
                || Context.Request.UserAgent.match(/crawler/i)
                || Context.Request.ServerVariables['REMOTE_ADDR'] == '127.0.0.1' // IPv4 only
          ]]></expression>
        </jscript>
    </or>
  </test>
</errorFilter>

直接複数の条件がある場合 <test> 論理的ではありません(<and> また <or>)次に、最初のもののみが使用されるので、それがあなたの <jscript> 1つは無視されていました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top