How to handle missing files on MVC

Posted by kaivalya on Stack Overflow See other posts from Stack Overflow or by kaivalya
Published on 2010-03-21T09:53:37Z Indexed on 2010/03/21 10:01 UTC
Read the original article Hit count: 429

Filed under:
|
|

What is your preferred way to handle hits to files that does not exist on your MVC app.

I have couple of web apps runing with MVC and they are constantly getting hits for files folders etc. that does not exist in the app structure.

Apps are throwing exception: The controller for path could not be found or it does not implement IController

I am trying to find out the best way to handle this.

I have 3 global routes on my global.asax file (see below) and at this point I am happy with that simple definition. I know if I added route definition for all controllers then I can add a definition to ignore the rest and handle these hits but if it will be possible to solve this problem without it, I do not want to add route definitions for each controller which I believe will flood the route definitions and also add a layer of maintenance which I don't like.

//Aggregates 2nd level
            routes.MapRoute(
                "AggregateLevel2",
                "{controller}/{action}/{id}/{childid}/{childidlevel2}",
                new { controller = "Home", action = "Index", id = "", childid = "", childidlevel2 = "" }
            );

            //Aggregates 1st level
            routes.MapRoute(
                "AggregateLevel1",
                "{controller}/{action}/{id}/{childid}",
                new { controller = "Home", action = "Index", id = "", childid = "" }
            );

            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = "" }
            );

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#