Friday, June 28, 2013

IIS Routing and Paths With 404 in Them

We had a problem today with a path routing.  We had a path similar to this http://localhost:54612/mydir/invoice/40414

It appeared that this path was never getting to the code, but being bounced back by IIS.  The URL http://localhost:54612/mydir/40399 worked just fine.

After further research we found that it was number at the end with 404 in it that was breaking us.  http://localhost:54612/mydir/30404 also broke.

The code we were using was

RouteTable.Routes.Add(new RegexRoute(@"^/mydir/invoice/(?\d+)/?$", new PathRouteHandler("~/myotherdir/file.aspx")));

Once we changed it to

RouteTable.Routes.Add(new Route(@"mydir/invoice", new PathRouteHandler("~/myotherdir/file.aspx")));

it worked.

We had to change the catching code to check the query string instead of the route path, but it worked.

We have yet to discover why it was behaving badly with invoice numbers containing 404.  I would love to read your thoughts if you have run across such a thing.