title: How to Debug URL Rewrite Rules in ASP.NET Web.config
body: <p><strong>[UPDATED QUESTION - 2020-03-06]</strong></p>
  
  <hr>
  
  <p>Here is my problem.</p>
  
  <p>I am working on an ASP.NET website, where the URL rewrite rules are very complex.</p>
  
  <p>As a result, it is difficult to discover which rules are matching for a particular URL.</p>
  
  <p>I would like help finding the ASP.NET classes, code or events that process the rules in the web.config so that I can trace through the process that takes place while the URL is being handled by IIS.</p>
  
  <p>I want to be able to see the URL and the result of each attempt to match a rule.</p>
  
  <p>Does anyone know a debugging technique to use in the Visual Studio debugger or some type of print statements that I can use to trace this process?</p>
  
  <p>Here is the documentation for the rewrite rules: <a href="https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference" rel="nofollow noreferrer">URL Rewrite Module Configuration Reference</a></p>
  
  <p>Below is an example that I have already debugged, showing the result of understanding the rules.  The rule "New2" is matched when testing.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;system.webServer&gt;
  ...
  &lt;rewrite&gt;
      &lt;rules&gt;
          &lt;rule name="Mobile"&gt;
              &lt;match url="^mobile$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="mobile.aspx" /&gt;
          &lt;/rule&gt;
          &lt;rule name="Print rule"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/print$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="print.aspx?url={R:1}" appendQueryString="true" /&gt;
          &lt;/rule&gt;
          &lt;rule name="New paging1"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/([A-Za-z0-9/_-]+)/([0-9]+)/page/([0-9]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?parent={R:1}&amp;amp;url={R:2}&amp;amp;godina={R:3}&amp;amp;page={R:4}" appendQueryString="false" /&gt;
          &lt;/rule&gt;
          &lt;rule name="New paging2"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/([0-9]+)/page/([0-9]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?url={R:1}&amp;amp;godina={R:2}&amp;amp;page={R:3}" appendQueryString="false" /&gt;
          &lt;/rule&gt;
  
          &lt;rule name="Page rule 1"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/([A-Za-z0-9/_-]+)/page/([0-9]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?parent={R:1}&amp;amp;url={R:2}&amp;amp;page={R:3}" appendQueryString="false" /&gt;
          &lt;/rule&gt;
  
          &lt;rule name="Page rule"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/page/([0-9]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?url={R:1}&amp;amp;page={R:2}" appendQueryString="true" /&gt;
          &lt;/rule&gt;
          &lt;rule name="New"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/([A-Za-z0-9/_-]+)/([0-9]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?parent={R:1}&amp;amp;url={R:2}&amp;amp;godina={R:3}" appendQueryString="false" /&gt;
          &lt;/rule&gt;
  
          &lt;rule name="New2"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/([0-9]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?url={R:1}&amp;amp;godina={R:2}" appendQueryString="false" /&gt;
          &lt;/rule&gt;
  
          &lt;rule name="rule 1"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)/([A-Za-z0-9_-]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?parent={R:1}&amp;amp;url={R:2}" appendQueryString="true" /&gt;
          &lt;/rule&gt;
          &lt;rule name="Glavni rule 2"&gt;
              &lt;match url="^([A-Za-z0-9/_-]+)$" ignoreCase="false" /&gt;
              &lt;action type="Rewrite" url="default.aspx?url={R:1}" appendQueryString="true" /&gt;
          &lt;/rule&gt;
      &lt;/rules&gt;
  &lt;/rewrite&gt;
  ...
  </code></pre>
  
  <p></p>