views:

51

answers:

1

I have an ASP.NET 4 WebForms application which is using routing. I would like to catch the 404's for routes that do not exist:

    RouteTable.Routes.MapPageRoute("404", "{*url}", "~/error");

Problem is, this will also cause a mapping to /error for pages like ImageHandler.ashx and Resource.axd.

So I add this:

    RouteTable.Routes.Ignore("{resource}.axd");
    RouteTable.Routes.Ignore("{handler}.ashx");

But this only ignores Resource.axd in the root directory, not in for example /scripts/Resource.axd.

How can I accomplish this? Or what Contraints should I set for the catch all PageRoute so it will only catch directories?

A: 

Did you try this?

RouteTable.Routes.Ignore("{*resource}.axd"); RouteTable.Routes.Ignore("{*handler}.ashx");

Patrick.Xiong