title | layout | permalink | article |
---|---|---|---|
Error Filtering Examples |
page |
a/error-filtering/examples/ |
true |
Do you have a handy error filter configuration that you have used time and time again? Why not share it? Drop it as a comment to this wiki and we'll add it here.
To learn more about how to filter harmless or noisy errors from your logs, see "Error Filtering".
Filter requests for favicon.ico that end in a 404 status code:
{% highlight xml %} {% endhighlight %}
Filter requests ending in 404 or those (using a jscript
assertion) where where the last raised VB error was a negative number:
{% highlight xml %} {% endhighlight %}
For background on the above filter, see the "Err.raise, how do I filter out custom error numbers..." thread in the discussion group.
Filters all exceptions that occur on local requests:
{% highlight xml %} {% endhighlight %}
Filter exceptions where the exception message contains certain words. In the example below, the words must be potentially, dangerous, value, detected and client and in the mentioned sequence. This will filter an exception where the message reads "A potentially dangerous Request.Path value was detected from the client".
{% highlight xml %} {% endhighlight %}
This example was created in response to the "Filtering HttpException: A potentially dangerous Request.Path value was detected..." thread in the discussion group.
Filter exceptions of type FileNotFoundException
only when an image is requested (request path ends in .jpg
, .gif
or .png
). In addition, filters exceptions resulting from compilation or parsing errors when the request is from local host and the application has debugging enabled (typical when developing dynamically compiled pages with in-line code).
{% highlight xml %} <![CDATA[ // @assembly mscorlib // @assembly System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a // @import System.IO // @import System.Web
// 404s for images
(($.HttpStatusCode == 404
|| $.BaseException instanceof FileNotFoundException)
&& $.Context.Request.Path.match(/\.(jpg|png|gif)$/i))
// Compilation errors during development
|| ($.Context.IsDebuggingEnabled
&& $.Context.Request.IsLocal
&& ($.BaseException instanceof HttpCompileException
|| $.BaseException instanceof HttpParseException))
]]></expression>
</jscript>
</test>
Filter exceptions of type TaskCanceledException
but only when the HTTP request method is HEAD and the user agent string contains the text "Microsoft Office Existence Discovery".
{% highlight xml %} <![CDATA[ // @assembly mscorlib // @import System.Threading.Tasks
// HEAD requests from Microsoft Excel that may cause
// TaskCanceledException to be raised
($.BaseException instanceof TaskCanceledException
&& 'HEAD' === $.Context.Request.HttpMethod
&& $.Context.Request.UserAgent.match(/\bMicrosoft\s+Office\s+Existence\s+Discovery\b/i))
]]></expression>
</jscript>
</test>
This error typically occurs when Microsoft Excel is setup with a Web Query to asynchronous request handler in your application.