views:

59

answers:

1

I can't exclude non-existing files from the routing system. I am dealing with this code in a Web Forms scenario:

public static void RegisterRoutes(RouteCollection routes)
{   
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  routes.IgnoreRoute("{resource}.gif/{*pathInfo}");
  routes.IgnoreRoute("{resource}.jpg/{*pathInfo}");   
  Route r = new Route("{*url}", new MyRouteHandler());
  routes.Add(r);
}

When I debug

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
    string path;

    IHttpHandler page;

    try
    {
        path = requestContext.RouteData.GetRequiredString("url");
        LogFile(requestContext, path);
    }

path still contains non existing gif files, jpg etc I want to exclude all files that have an extension if that’s possible

Is something wrong with the code above? Is the order correct, i.e. add routes.IgnoreRoute entry prior to adding a route to RouteCollections?

A: 

IgnoreRoute is an extension method of ASP.NET MVC (System.Web.Mvc) - does not work in Web Forms.

Do this:

routes.Add(new Route("{resource}.gif/{*pathInfo}", new MyIgnoreHandler()));

Map your other routes to your regular handler.

You should remove the "mvc" tag from this question.

RPM1984