5

I have a brand new asp.net mvc 3 project. I did not modify the routes in any way. I have a controller called PageController and another controller call ContentController.

When I browse to domain.com/Page then the Index action on the Page controller gets executed as expected and displays the Index view.

When I browse to domain.com/Content I get a 404 error. If I browse to domain.com/Content/Index then it works fine.

How do I troubleshoot this single route?

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        ); 
    }

I tried adding an additional route:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        ); 
        routes.MapRoute(
             "Content", // Route name
             "Content/{action}/{id}", // URL with parameters
             new { controller = "Content", action = "Index", id = UrlParameter.Optional } // Parameter defaults
         );

    }

But the additional route did not change the application's behavior.

What could be causing this?

2
  • Just to clarify, can you add the code for the ContentController Sep 28, 2011 at 15:59
  • @MatthewAbbott - It's all generated through scaffolding. I was able to resolve the issue by implementing Nathan's answer.
    – quakkels
    Sep 28, 2011 at 16:15

2 Answers 2

11

its because there is a physical folder called content. having a controller with the same name as a physical folder will probably have some adverse affects on your website.

2
  • Huh... this makes sense. I'll try renaming the controller.
    – quakkels
    Sep 28, 2011 at 16:10
  • Just ran into this after banging my head against the wall for abit, thanks for the answer!
    – Wil
    Jan 24, 2012 at 14:51
0

Try adding the following to your route definitions:

routes.RouteExistingFiles = true;
2
  • won't he then have to set up routes or ignore routes for his actual content files? Sep 28, 2011 at 16:07
  • I betcha this would work. But, I think the root problem is outlined by @nathangonzalez.
    – quakkels
    Sep 28, 2011 at 16:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.