title: Executing a managed module for a rewritten URL in IIS7 Integrated Mode
body: <p>In my ASP.NET app, I have two HTTP modules. One of them is used for rewriting URLs, the other is used for app-specific stuff (custom authentication .. etc). The URL-Rewriting module is executed for all requests, while the other module is only executed for managed file extensions, like .aspx</p>
  
  <p>Here's how the modules are defined in web.config (note that preCondition is blank for UrlRewriteModule. This cause it to get executed for all requests):</p>
  
  <pre><code>&lt;system.webServer&gt;
    &lt;modules&gt;
      &lt;add name="UrlRewriteModule" type="MySite.UrlRewriteModule" preCondition="" /&gt;
      &lt;add name="SiteModule" type="MySite.SiteModule" preCondition="managedHandler" /&gt;
    &lt;/modules&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>In UrlRewriteModule I use RewritePath() to rewrite some URLs (directory-like) into files with query strings. For example, from "/p/5/some-thoughts-about-the-future/" to "/post.aspx?id=5"</p>
  
  <p><strong>Now, I was under the impression that when a URL gets rewritten, IIS7 executes the managed module (SiteModule in this case) if the new URL is for a managed extension (like .aspx). But, this doesn't seem to be the case. I noticed that SiteModule doesn't get executed for any rewritten URLs.</strong></p>
  
  <p>Am I missing something (or doing something wrong) or is this the normal behavior in IIS7?</p>
  
  <p>I came across Server.TransferRequest() which actually solves the problem (behind the scence, it involves creating a new child request). But, this can also <a href="http://forums.iis.net/p/1146511/1857303.aspx" rel="nofollow">cause a lot of overhead</a> esp. under server load, and I generally prefer to avoid it.</p>
  
  <p><strong>So, is there a way to get SiteModule to execute whenever a URL gets rewritten without using Server.TransferRequest()?</strong></p>
  
  <p>Thanks!</p>