Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting MVC to ignore route to site root

I'm working on a site that is partially static content and partially MVC. The root of the site is index.html and I have all of the controllers explicitly routed and all html files ignored. However, when you hit the root of the website, it tries to route it. How can I tell the route engine to ignore the root of the site? www.mysite.com should not be routed, but instead go to index.html. Here is my routing configuration:

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("*.html|js|css|gif|jpg|jpeg|png|swf");

        routes.MapRoute(
            "vendor_signup","{vendor}/signup/{action}/",
            new { controller = "Signup", action = "Index", vendor=UrlParameter.Optional}  // Parameter defaults
        );
        routes.MapRoute(
            "signup","signup/{action}/",
            new { controller = "Signup", action = "Index", vendor=Vendors.PCICentral}  // Parameter defaults
        );
//more routes below
like image 363
John Teague Avatar asked Jun 30 '10 15:06

John Teague


2 Answers

I believe what you mean is when someone accesses / on your website, you don't want to use MVC, but show a static page. To achieve this, you need to tell MVC to ignore that route and let webforms handle it. Webforms then should show you /index.html when it gets the request /.

Simply adding this before your routes should work:

routes.IgnoreRoute("");
like image 85
René Wolferink Avatar answered Sep 20 '22 15:09

René Wolferink


One of the routes was still in {} which made it try to parse the root.

like image 33
John Teague Avatar answered Sep 22 '22 15:09

John Teague