Allrameest
Allrameest

Reputation: 4492

How do I block access to files when using the System.Web.Routing.UrlRoutingModule?

I'm using the System.Web.Routing.UrlRoutingModule.

With that I'm writing:

routes.Add(new Route(@"cart/add", new RouteHandler("~/Order/CartAdd.ashx")));
routes.Add(new Route(@"cart/delete", new RouteHandler("~/Order/CartDelete.ashx")));
...

And I also have one route called:

routes.Add(new Route(@"{*url}", new RouteHandler("~/Error/PageNotFound.ashx")));

But if I go directy to /Order/CartAdd.ashx I never enter the routing. It goes directly to that handler. And if I go to /Order/ I get a 403.14 error.

How do I instead catch those urls with the routing?

Upvotes: 1

Views: 246

Answers (1)

Sciolist
Sciolist

Reputation: 1829

In your route registration code, you can write something like this..

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.RouteExistingFiles = true;
        routes.IgnoreRoute("default.aspx");
        [...]

Which should force file requests through your routing rules.

Upvotes: 1

Related Questions