Q:

Page Load fires twice after url rewriting

I have a page (DetaliiProdus.aspx) where I've applied this url rewriting rules:
 <rewrite>
    <rules>
      <rule name="DetaildProductSub1" stopProcessing="true">
        <match url="produse/([_0-9a-z-]+)/([0-9]+)/([0-9]+)/([_0-9a-z-]+)" />
        <action type="Rewrite" url="Site/DetaliiProdus.aspx?c={R:1}&amp;p={R:2}&amp;s1={R:3}" appendQueryString="false"/>
      </rule>
      <rule name="DetaildProductSub1Sub2" stopProcessing="true">
        <match url="produse/([_0-9a-z-]+)/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-z-]+)" />
        <action type="Rewrite" url="Site/DetaliiProdus.aspx?c={R:1}&amp;p={R:2}&amp;s1={R:3}&amp;s2={R:4}" appendQueryString="false"/>
      </rule>
    </rules>
  </rewrite>

If I am going to the page directly as you see in the action url (eg:"/Site/DetaliiProdus.aspx?c=m1&p=868&s1=60&s2=140") the Page Load is fired once and all works great.
If I am going to the page using the url rewrite rule: (eg:"/produse/m1/868/60/140/Biserica%20in%20asediu") the Page Load method is fired multiple times (3 times).
Can you give me any clue why this issue occurs? I've already spent over 3 hours on this:(...

A:

Look for additional resources being loaded and passed through your routing rules to your handler page - if there are .js, .css, etc. files being loaded for the page, the form load can fire multiple times during rerouting. When this occurs, you can test the HttpContext object to see what the name of the requested resource is and then abort processing if necessary.
It is preferable to filte requests earlier in the pipeline, but if your page load is being called multiple times, consider filtering in the page load (or page init, etc).

