I recently updated the Intrepid Studios site back-end to include ELMAH, the error reporting module. ELMAH is great and works great, except that it doesn't play nice with UrlRewritingNet.

There is a StackOverflow discussion about this with a workaround that ended up not using UrlRewritingNet at all unfortunately. In addition, there's a detailed post about doing some voodoo and mixing potions to get UrlRewritingNet to work. Note that you can simply remove the defaultPage attribute on the urlrewritingnet config section to solve this, but it may cause other unintended consequences.

I thought to myself, there's gotta be a better way! And there is (well, it's a hack so I suppose it is not entirely the best, but it is the simplest so far). I simply added in a few lines of code to the UrlRewritingNet source code to allow you to ignore URLs. Without knowing much about how the component works, this is an easy "patch."

Download the Modified Binaries

For those that don't care how I did it, I have uploaded the modified binaries you'll need to replace in your application. See below for an explanation of how to use it.

Getting the Source

Head over to the Downloads section of UrlRewritingNet to get the source code.

Extract the files to a directory of your choice.

I opened and converted the solution with VS 2010, but you can use anything you wish.

Modifying the Files

We will modify 3 files. Follow along below.

In WebRewriteOption.cs, add another value to the enumeration like so:

[Flags] 
public enum RewriteOption
{
    Application = 0x00,
    Domain = 0x01,
    None = 0x02 // KR: Ignore the URL
}

In WebUrlRewriteModule.cs, around line 212, add the following underneath if (rewrite.IsRewrite(requestUrl)):

//KR: ignore url
if (rewrite.Rewrite == RewriteOption.None)
{
    rewritten = true; // sure, we totally "rewrote" it, heh.
    break;
}

In urlrewritingnet.xsd, change the xs:simpleType for RewriteOption to be:

<xs:simpleType name="RewriteOption">
  <xs:restriction base="xs:NMTOKEN">      
    <xs:enumeration value="Application" />
    <xs:enumeration value="Domain" />
    <xs:enumeration value="None" /> <!-- KR Ignore URL -->
  </xs:restriction>
</xs:simpleType>

Finally, in the same file, change the use="required" attribute of destinationUrl to be optional, like so:

<xs:attribute name="destinationUrl" type="xs:string" use="optional" />

Build the solution in Debug/Release and copy over the new DLLs to your project. Voila, all done! Now all you need to do to NOT rewrite a URL is the following:

<add name="Elmah"
  virtualUrl="^~/elmah.axd(.*)$"
  rewrite="None"
/>

I've tested it with Intrepid Studios and it seems to work just fine.

As always, feedback and improvements are much appreciated!