开发者

Getting MVC to ignore route to site root

开发者 https://www.devze.com 2023-01-05 18:53 出处:网络
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, whe

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.P开发者_运维百科CICentral}  // Parameter defaults
        );
//more routes below


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("");


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

0

精彩评论

暂无评论...
验证码 换一张
取 消