Getting MVC to ignore route to site root

走远了吗. 提交于 2019-12-10 03:06:11

问题


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

回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/3150747/getting-mvc-to-ignore-route-to-site-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!