0

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?

1
  • No luck with my below answer? Commented Jul 2, 2010 at 6:57

2 Answers 2

1

In Web Forms, you can use the StopRoutingHandler. In the following example, routing will be ignored for files in the /images folder like http://yoursite.com/images/xyz.jpg

routes.Add(new Route("images/{resource}", new StopRoutingHandler())); 
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.