Custom Filtering for User Agent and Server Side Error Message

402 views
Skip to first unread message

Eeyore145

unread,
Oct 5, 2009, 8:04:44 PM10/5/09
to ELMAH
I have been using ELMAH for about 9 months and I absolutely love it. I
have a question that I hope the community can help me with.

We have been getting the IE 8 Lookahead bug, or the missing 4096K from
scriptresource and webresource.axd. I have been in contact with
Microsoft and we basically have resolved this issue doesn't affect the
end user and until Microsoft actually fixes the bug for IE 8 there
isn't a feasible work around.

So at this point, I want to filter this error out of ELMAH. Here is my
issue. The filter rule is basically this:

BASEEXCEPTION IS System.Web.HttpException

AND

MESSAGE IS "Invalid viewstate."

AND

User-Agent Contains Trident\4.0

Basically this bug only occurs in IE 8 and IE 8 compatibility mode. So
I know through a javascript such as this:

function IsIE8Browser() {

var rv = -1; var ua = navigator.userAgent; var re = new RegExp("Trident
\/([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null) { rv = parseFloat(RegExp.$1); }
return (rv == 4);
}

whether or not the browser is IE 8. But I don't know how to get this
function and the regex check on trident into a jscript expression
ELMAH will understand.

Also this would need to be paired with a check that validates the
error message contains "Invalid ViewState", we probably don't need to
check the BaseException, Invalid ViewState and IE 8 check is probably
enough.

I was looking at doing this declaratively but I can't get the syntax
right to probe the base exception and get the message and also inject
client side script to parse the user agent. I could potentially do
this server side, but does that mean I have to write a custom
assertion.

Can you provide any insight?

Thanks in advance for your help

Atif Aziz

unread,
Oct 6, 2009, 5:46:39 PM10/6/09
to el...@googlegroups.com
I believe this should do the trick:
 
<errorFilter>
  <test>
    <and>
      <is-type binding='Exception'
               type='System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' />
      <regex binding='Exception.Message'
             pattern='invalid\s+viewstate'
             caseSensitive='false' />
      <regex binding='Context.Request.UserAgent'
             pattern='Trident/4(\.[0-9])*'
             caseSensitive='false' />
    </and>
  </test>
</errorFilter>
 
 
Also available at:
 
- Atif

Tony Bunce

unread,
Oct 6, 2009, 6:39:13 PM10/6/09
to el...@googlegroups.com

I am using this filter to serve the same purpose:

       <errorFilter>

           <test>

                 <and>

                       <regex binding="Context.Request.ServerVariables['HTTP_USER_AGENT']" pattern="Trident\/4\.0" />

                       <equal binding="Context.Request.ServerVariables['URL']" value="/MyApp/ScriptResource.axd" type="String" />

                 </and>

           </test>

       </errorFilter>

 

We only check that the browser is IE8 and that the URL is ScriptResource.axd because we see errors other than invalid view state (Base64 errors I think).  You could toss an <or> in there if you want to also include webresoruce.axd.

 

-Tony

Eeyore145

unread,
Oct 6, 2009, 8:10:41 PM10/6/09
to ELMAH
Tony and Atif:

Thanks for your replies.

Yes, it appears we are facing the same issue. Just one question. We
get it for WebResource and ScriptResource axd so how do I add the <or>
is it this?

<errorFilter>
<test>
<and>
<regex binding="Context.Request.ServerVariables
['HTTP_USER_AGENT']" pattern="Trident\/4\.0" />
<equal binding="Context.Request.ServerVariables
['URL']" value="/MyApp/ScriptResource.axd" type="String" />
<or>
<equal
binding="Context.Request.ServerVariables['URL']" value="/MyApp/
WebResource.axd" type="String" />
</or>
</and>
</test>
</errorFilter>

Is that it? How do I nest or declare the conditions properly, sorry
I'm new to ELMAH. The condition is:

UserAgent Containd Trident\/4\.0

AND

(URL is ScriptResource.axd OR Url is WebResource.axd)

So how do I position my test statement blocks?

Atif Aziz

unread,
Oct 9, 2009, 5:59:11 PM10/9/09
to el...@googlegroups.com
Like this:
 
<errorFilter>
  <test>
    <and>
      <regex
        binding="Context.Request.ServerVariables['HTTP_USER_AGENT']"
        pattern="Trident\/4\.0" />
      <or>
        <equal
          binding="Context.Request.ServerVariables['URL']"
          value="/MyApp/ScriptResource.axd"
          type="String" />
        <equal
          binding="Context.Request.ServerVariables['URL']"
          value="/MyApp/WebResource.axd"
          type="String" />
      </or>
    </and>
  </test>
</errorFilter>
Reply all
Reply to author
Forward
0 new messages